Introduction
Variables in PowerApps can be used for a variety of purposes, such as storing user input, performing calculations, and passing data between screens. In this blog post, we will discuss the different types of variables in PowerApps and how they can be used.
Global Variables in PowerApps
Global variables in PowerApps are used to store values that can be accessed across the entire app. These variables can be initialized with a default value or left empty to be populated later. Global variables can be created and modified in the App OnStart property.
Syntax
Set(varName, varValue)
Example
Set(language, "English")
Context Variables in PowerApps
Context variables are used to store temporary data that is specific to a screen or control. These variables are only available within the context of the screen or control where they are created. Context variables can be created and modified in the screen's OnVisible property or in the control's OnSelect property.
Syntax
UpdateContext({varName: varValue})
Example
UpdateContext({calcResult: 2 + 2})
Collection Variables in PowerApps
Collection variables in PowerApps are used to store a collection of data, such as a table of records or a list of values. Collection variables can be initialized with data from a data source or created from scratch. Collection variables can be created and modified in the app OnStart property or in the screen OnVisible property.
Syntax
ClearCollect(collectionName, data)
Example
ClearCollect(productList, Filter(Products, Category = "Electronics"))
Summary
The article discusses the three types of variables in PowerApps- global, context, and collection variables. Each type of variable has its purpose and can be created in different properties of the app. Syntax and examples are provided for each type of variable.