Power Apps Standards: Variable Types
Power Apps Standards: Variable Types Table of Contents Variable Scope Usage Examples Why Use Global And Local Variables? Variable Scope A variable’s scope de...
- Published
- Reading time
- 2 min read
Before you start
Is this guide for you?
- Best entry point
- Power Apps
- Time investment
- 2 min read
Imported reference from Matthew Devaney's blog for learning purposes. Original: https://www.matthewdevaney.com/power-apps-coding-standards-for-canvas-apps/power-apps-standards-variable-types/. Author: Matthew Devaney.
Power Apps Standards: Variable Types Table of Contents Variable Scope Usage Examples Why Use Global And Local Variables? Variable Scope
A variable’s scope determines where it can be referenced in the app. If the variable is required on multiple screens use a global variable. Otherwise, use a local or context variable instead. Choose the proper variable type by determining its scope. Variable Type Declaration Method Scope Global Set Function
Variable is available across all app screens Local UpdateContext Function
Variable is only available on a single app screen One-time With Function
Variable is only available inside the WITH function Usage Examples Global Variable (SET function) Set ( gblSalesTaxAmount , Value ( txt_OrderForm_SubtotalAmount .Text ) * 0 .13 ); Code language: CSS ( css ) Local Variable (UPDATECONTEXT function) UpdateContext ( {
locLineItemsCount : 0 , locShowConfirmationMenu: false, locOrderFormMode= Blank () } ); Code language: CSS ( css ) One-Time Variable (WITH function)
With ( { varBusinessContact : LookUp ( 'Sales Orders' , ID=ThisItem.ID)}, Concatenate ( varBusinessContact .FirstName , " ", varBusinessContact .LastName ); Code language: CSS ( css ) Why Use Global And Local Variables?
Imagine a large canvas app with many screens that only uses global variables . When updating a variable’s value the developer must be aware of its impact across all screens. If the developer does not correctly determine how to use a variable there are unintended consequences (i.e. a software bug).
Local variables can only be used on one screen. Developers have an easier time assessing the impact to a single screen as opposed to many screens. Higher quality code can be written at a faster pace.
One-time variables are not persistently stored in memory. After the With function is executed the variable is cleared from memory and cannot be accessed outside of the function. Did You Enjoy This Article? 😺
Subscribe to get new Copilot Studio articles sent to your inbox each week for FREE Enter your email address Sign Me Up Questions?
If you have any questions about Power Apps Standards: Variable Types please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.
Tagged
Power Apps
Have a Microsoft 365 topic idea?
Share article suggestions, community session ideas, corrections, or real-world scenarios for future nextM365 learning notes.
Keep learning Microsoft 365
Explore more practical guides for SharePoint, Power Platform, Copilot Studio, migration, automation, governance, and security.
Continue learning
Related tutorials
Related questions
Related comparisons
Next action