Add variables to a card
Variables store data for reuse. The data can be of different types, like collection, text, or a number. Variables have unique names, which is how you refer to them in Power Fx formulas. Insert, modify, and remove them in the card designer.
The value of a variable can be temporary, reset for each card session, or permanent, shared across all sessions of a specific card instance. Temporary variables are different for each card session, even for a single user, meaning if you have the same card instance sent to you in a chat and a channel, a temporary variable could be different across those two sessions.
As an example, you've created a card that counts how many times the user presses a button during a session. You would create a temporary number variable to store the number of button presses in the current instance of the card. If you also want to capture the name of the last user to press a button in a card instance, you would store it in a permanent text variable. If you further want to save the data between card instances, you would use a data connection.
Variables can also be customizable, which means the value is set by the sender, whether that is in the Play Page before sending as a link or in Power Automate as part of the Create a card instance action.
Prerequisites
- A Power Apps account
- A card
Create a variable
Sign in to Power Apps. Select Cards, and then select a card. If the Cards tab is not visible, select More and pin the Cards tab.
In the left pane of the card designer, select Variables
Select + New variable.
In the New variable window, set the following values:
- Name: The name of your variable (Required)
- Type: The type of variable (Required)
- Default value: The default value of the variable
- Persistence: Whether the variable is temporary (resets every time the card is opened) or permanent
- Customization: Whether the variable is customizable by the sender so it acts as an input variable
You can't change the name or type of a variable. If you need to change them, create a new variable.
You can also customize sender options and, under Additional variable information, the Title and Description of the variable. This information may be helpful for testing, debugging, and using your variable with Power Automate flows.
Select Save.
Using the default value for tables and records
The default value is used to set the structure for collection and record variables. There are two ways to set the default value of a record or table variable:
- Using the column editor
- Using Power Fx / JSON
You can toggle between whether you are using column editor or Power Fx / JSON using the toggle on the right.
Using a Power Fx expression is helpful when you want the variable to store data from a data source, like Dataverse. For example, if you wanted a record that held a specific row from the Account table, you could set the default value to First(Account)
.
Variables are strongly typed and so setting the default value locks the variable into those types.
Edit and delete variables
To edit or delete a variable, select the ellipsis (...) to the right of the variable, and then select Edit or Delete.
Use variables in cards
There are various ways to use variables in cards. Learn about working with variables in Power Apps.
A common use for variables is in Power Fx expressions. Refer to the variable by name in your formula. For an example, go to the simple card tutorial. Your variables are recognized in the formula bar as well.
Updating the value of a variable
Variables can be updated using the Set function, excluding table variables which are added to using the Collect function.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for