Mastering Power Fx in Copilot Studio: Using Variables in Formulas and Key Functions

How to use topic variables and global variables within formulas in Copilot Studio.

スポンサーリンク

Formulas (Power Fx Expressions)

In Copilot Studio, you can use Power Fx expressions similar to Power Apps in various scenarios, such as asking questions, setting variables, or sending messages.

This time, I explored various aspects of these formulas.

Available Functions

The Power Fx functions available in Copilot Studio are only a subset of the full set (as expected, some functions like `PDF` or `SaveData` are not supported).
Official documentation on available functions can be found here.
Create expressions using Power Fx - Microsoft Copilot Studio
Use Power Fx to create complex agent logic using formulas to manipulate data in Microsoft Copilot Studio.
Interestingly, functions like `Sequence`, which are not listed in the official documentation, can still be used. It’s worth trying even if a function isn’t listed.

Operators

All operators seem to be supported, including basic arithmetic operations, comparisons (greater than, less than), and even functions like `in`.
However, using string interpolation syntax seems a bit unreliable.
This may be because Copilot Studio’s code inherently utilizes string interpolation syntax.

Complex Formulas Are Possible

Functions listed in the official documentation, such as `ForAll` and `Filter`, are of course supported, but even functions like `With` can be used. This allows for writing relatively complex formulas.
*Example: Outputting a table of squared values greater than or equal to 6 from the first 10 natural numbers.
When writing longer formulas, click the expand button in the top-right corner for easier editing.

Using Constants

To assign literal values (fixed strings, numbers, etc.) to variables, you can use formulas.

Using Variables in Formulas

When accessing variables in formulas, you must prefix them as follows:

  • System Variables: `System.`
  • Global Variables: `Global.`
  • Topic Variables: `Topic.`
For example, using a topic variable in a formula looks like this:
Using a global variable in a formula:
Environment variables, though not officially documented, can be accessed using the `Env.` prefix:

Handling Arrays

While you can declare arrays in Power Fx formulas, they are treated as object arrays (tables) rather than pure arrays, similar to Power Apps.

For example, declaring `[1,2,3,4,tes a table like `[{Value:1}, {Value:2}, …]`.

Comments

You can add comments within formulas, which is especially helpful for clarifying complex expressions.

Related Articles

コメント

Copied title and URL