The Comment-Generated Formulas feature in Power Apps lets you create Power Fx formulas directly from code comments. By typing `//` or ‘/*’ followed by a natural language instruction, Copilot can generate a relevant Power Fx formula tailored to your app’s context. You can choose to accept Copilot’s suggestion or edit the formula, using comments as convenient documentation for each formula.
This tool is now available and supports multiple languages beyond English, making it accessible for users worldwide. Languages like French, Spanish, and German are now supported, allowing you to direct Copilot in your preferred language. To see the list of supported languages, refer to the official documentation on Supported Languages.
Prerequisites
Copilot must be enabled in your environment. For additional guidance, refer to the documentation on how to enable or disable Copilot in Power Apps.
The new formula bar is enabled by default. If the Copilot menu isn’t visible, review your app settings in Power Apps Studio:
- In the command bar, go to Settings.
- Now navigate to Updates, and enable the option for Copilot comment-generated formulas.
- In the “Retired” tab, disable the toggle for “Legacy formula bar.”
With these settings, you’ll be ready to take full advantage of Copilot’s AI-powered formula generation in Power Apps, simplifying formula creation with natural language.
Create Power Fx Formulas Instantly from Comments
In Power Apps, Copilot allows you to generate Power Fx formulas directly from comments entered in the formula bar. Simply type a comment using `//` or `/*`, and Copilot will suggest a formula based on your comment.
- Open your Canvas app in edit mode.
- Type a comment in the formula bar by starting with `//` or `/*`.
Example: // Calculate total expenses
- Give Copilot a moment to suggest a formula, or press “Enter” to create it immediately.
In the example below, I’ve created an expense calculator app in Power Apps and used a code comment to generate a formula to calculate pending expenses.
Example Code Comment:
// Concatenates a dollar sign with the formatted sum of costs from the LineItems2 table where the ReportID is found in the PendingReports table, but only if that sum is greater than zero; otherwise, it shows zero.
AI-Generated Formula:
If(Sum(Filter(LineItems2, ReportID in ShowColumns(PendingReports, ID)), Cost) > 0, “$” & Text(Sum(Filter(LineItems2, ReportID in ShowColumns(PendingReports, ID)), Cost), “$#,##0.00”, “en-US”), “$0”)
To use the suggested formula, press ‘Tab’ to accept it. You can continue typing to adjust the formula as needed.
If Copilot doesn’t offer a suggestion, it means it couldn’t generate a formula based on your comment. Try rephrasing the comment to improve results. It’s recommended to enclose elements you want to include in your formula in quotes, such as “PendingReports.ID” and “LineItems2”.
Now Available with Multi-Language Support
The Generating Power Fx formula using Copilot now supports multiple languages! To see the list of supported languages, refer to the official documentation on Supported Languages.
Let’s try the example in Spanish:
Example Code Comment:
// Concatena un signo de dólar con la suma formateada de costos de la tabla LineItems2 donde el ReportID se encuentra en la tabla PendingReports, pero solo si esa suma es mayor que cero; de lo contrario, muestra cero.
By using this comment in Spanish, Copilot generated the same formula as in the original example.
Some limitations when generating formulas from code comments:
- It works only on the specific control and property you are focused on, and won’t modify other controls or properties to achieve the desired result.
- Copilot doesn’t consider any existing formula text that is already present.
- It only recognizes the default properties in Power Apps, and are limited to supporting general Power Fx functions.
- User-defined functions are not recognized by Copilot.
- Functions specific to Power Apps, like `Navigate()`, aren’t supported in code comments.
- The advanced panel doesn’t trigger formula suggestions.
- Copilot won’t include existing formulas for the property in its suggestions.
Conclusion
Copilot in Power Apps makes creating Power Fx formulas easier than ever by generating them directly from comments. With multi-language support, users can now work in their preferred language, improving accessibility. This feature simplifies formula creation, enhances documentation, and speeds up app development. Enable Copilot in your environment and let it streamline your Power Apps experience.