Global Set Variable

Each object or property we use in Power Apps can be used as a variable. For example, we can set the value of a TextBox as TextBox1.Text and this way, it is defined as a variable that has a text value and that can be interfered by the users. Even though every object can be used as a variable, there are real functions designed to be a variable. These functions that are experts in assigning an using variables are used in more dynamic actions like calculating a value in an increasing or decreasing way, rather than a static Label moving data between pages. Set variable is one of them.

Properties

  • It’s a global/general variable, can be applied from all the screens of the app.
  • It can be created and applied anywhere in the app.
  • It can hold different data types like Numbers, Text string, Boole, Record and Table.
  • Set(variable_name; value)

Set Variable

It is a very easy-to-use function. You define the variable name and state the value that will be written in it. And then, the variable name is written in the required field and the data it contains is open to use.

Let’s practice with a counter example by creating a variable.

Add a TextBox and two buttons into the screen and position them like below.

Write + and – on the buttons. Set() functions will be written in the OnSelect property of buttons.

+ button: Set( Counter; Counter+1)

With this formula, the last value of the counter is increased by 1 and the data is transmitted to the counter again.

– button: Set( Counter; Counter-1)

With this formula, the last value of the counter is decreased by 1 and the data is transmitted to the counter again.

Label: Counter

Name of the variable is written in to the Text property of the Label and the value the variable holds is reflected on the screen.

Click here for the general usage of the function.

You can access the other Power Apps articles here.

Variable Types

Each object or property we use in Power Apps can be used as a variable. For example, we can set the value of a TextBox as TextBox1.Text and this way, it is defined as a variable that has a text value and that can be interfered by the users. All the values like the color of an object, the text, borders can be used. From this point of view, we can see all the objects as variables. You can take a look here to read other article concerning this topic.

Even though every object can be used as a variable, there are real functions designed to be a variable. These functions that are experts in assigning an using variables are analyzed under 3 categories for Power Apps. They are used in more dynamic actions like calculating a value in an increasing or decreasing way, rather than a static Label moving data between pages.

Power Apps Variable Types

1-General Variables:

Set

  • It’s a global/general variable, can be applied from all the screens of the app.
  • It can be created and applied anywhere in the app.
  • It can hold different data types like Numbers, Text string, Boole, Record and Table.
  • Set(variable_name; value)

2-Context Variables:

UpdateContext

  • they can be applied from one screen only.
  • a single value, a record, a table, an object reference, any result from a formula
  • UpdateContext({variable_name : value })

3-Collection: 

Collect & ClearCollect

  • Holds tables that can be created and applied anywhere in the applications.
  • Saved in the local device to be used later.
  • Different data can be enter based on columns or rows in a table.
  • Every time collect is created, writes the data on top of each other.
  • ClearCollect deletes an existing table and recreates it from scratch every time.
  • Collect( table name ;{column1: “value1” ; column2: “value2”; column3: “value3” ;…})
  • Collect( table name ;{column1: “value1” ; column2: “value2”}; {column1: “value1” ; column3: “value3”} ; {…})

You can click here to take a look at the other article concerning the usage of collections.