Use the Set function to set the value of a global variable, which temporarily holds a piece of information, such as the number of times the user has selected a button or the result of a data operation.
Global variables are available throughout your app on all screens. These are the simplest kind of variables and fill the needs of most situations. There are also context variables which are scoped to a single screen and collections that allow row level modifications to tables. For more information about these other options, review Understand variables.
Power Apps are based on formulas that automatically recalculate as the user interacts with an app. Any formulas that depend on a variable will automatically update when it changes. However, the variable won't be automatically updated if the value of the formula used in the Set function changes. This requires the app maker to manually update the variable, which can be error prone and harder for others to understand. Before you use a variable, review Understand variables.
Global variables are implicitly created by using the Set function. No explicit declaration is required. If you remove all the Set functions for a global variable, that global variable will cease to exist. To clear a variable, set its value to the result of the Blank function.
You can see your variables' values, definitions, and uses with the Variables view under the File menu in Power Apps Studio.
As the examples later in this topic show, global variables can hold several kinds of information, including these:
a single value
a record
a table
an object reference
any result from a formula
A global variable holds its value until the app is closed. Once closed, the global variable's value will be lost and must be recreated when the app is loaded again.
Global variables cannot use the same name as an existing collection or control. It can use the same name as a context variable. To disambiguate between the two, use the disambiguation operator.
Set has no return value, and you can use it only within a behavior formula.
Syntax
Set( VariableName, Value )
VariableName - Required. The name of a global variable to create or update.
Value - Required. The value to assign to the context variable.
Examples
Watch Talks with Aroh Shukla on Power Apps-Session 2
The Tech Platform
Source: microsoft
Comments