What's The Difference Between These Power Apps Functions?
What’s The Difference Between These Power Apps Functions? Posted by - Matthew Devaney on - July 6, 2020 4 Comments “There’s more than one way to skin a cat ....
- Published
- Reading time
- 7 min read
Before you start
Is this guide for you?
- Best entry point
- Power Apps
- Time investment
- 7 min read
Imported reference from Matthew Devaney's blog for learning purposes. Original: https://www.matthewdevaney.com/whats-the-difference-between-these-powerapps-functions/. Author: Matthew Devaney.
What’s The Difference Between These Power Apps Functions? Posted by - Matthew Devaney on - July 6, 2020 4 Comments
“There’s more than one way to skin a cat .”
As a cat-lover, I dislike this graphic-reference to taxidermy. But it does have a point: there are often multiple ways to achieve a goal.
In this article I will compare 6 pairs of Power Apps functions, why they are the similar and how you can use their differences to your advantage. RGBA vs COLORVALUE function
The RGBA and COLORVALUE functions can both output the same colors but they require different inputs. Here’s an example: Color RGBA(Red,Green,Blue,Alpha) ColorValue(CSSColor) RGBA(138, 43, 226, 1) ColorValue(“#8a2be2”)
RGBA gives Power Apps makers the ability to adjust the transparency of a color by setting the Alpha property. This is useful for creating overlays.
COLORVALUE takes text-based hex value as an input which means you can easily store it in a SharePoint list and use it across several apps to ensure consistent branding. PowerAppsColors (SharePoint List)
Put this code in the OnStart property of your app to store the colors in a global variable. Then you can refer to a color by typing varColors.Primary1 Set (varColors,
Primary1 : ColorValue(LookUp(PowerAppsColors, Title= "Primary1" , HexValue)),
Primary2 : ColorValue(LookUp(PowerAppsColors, Title= "Primary2" , HexValue)),
Secondary1 : ColorValue(LookUp(PowerAppsColors, Title= "Secondary1" , HexValue)),
Secondary2 : ColorValue(LookUp(PowerAppsColors, Title= "Secondary2" , HexValue)), ) Code language: JavaScript ( javascript ) ISBLANK vs ISEMPTY function
ISBLANK and ISEMPTY both check for the absence of any value. Suppose you have a SharePoint list with some Cities: Locations (SharePoint List) City New York London Paris
You might want to check if the city “Tokyo” exists in City column. The code below will return true because “Tokyo” cannot be found using the LOOKUP function.
IsBlank(LookUp(Locations, City= "Tokyo" )) Code language: JavaScript ( javascript )
Another approach would be to use a FILTER function and check whether any results were found. // The output of this formula is false
IsBlank(Filter(Location, City= "Tokyo" )) // The output of this formula is true
IsEmpty(Filter(Location, City= "Tokyo" )) Code language: PHP ( php )
Why does ISBLANK return false ? The empty table counts as value even though it has no records. Therefore, you must apply ISEMPTY to find the expected result of true . CONCATENATE vs CONCAT
CONCATENATE and CONCAT each join multiple text strings together into a single text string.
In this example CONCATENATE merges several individual email addresses into a format used when sending a message to multiple people. // load emails into variables
Set(varEmail1, " [email protected] ); Set(varEmail2, "
[email protected] ); Set(varEmail3, " [email protected] );
// join together emails with a separator Concatenate(varEmail1, " ; ", varEmail2, " ; ", varEmail3" )
>> Result: [email protected] ; [email protected] ; [email protected] ; Code language: PHP ( php )
The “&” symbol is a short-hand for CONCATENATE and also produces the same result
// alternate method to join emails with a separator
varEmail1 & "; " & varEmail2 & "; " & varEmail3 Code language: JavaScript ( javascript )
What if the emails were stored in a table like this instead? Employees (SharePoint List) CompanyEmail [email protected] [email protected] [email protected]
CONCAT can extract the Email Address on each row of CompanyEmail and convert them into a single text string.
// join together emails with a separator Concat(Employees, CompanyEmail & "; " )
>> Result: [email protected] ; [email protected] ; [email protected] ; Code language: JavaScript ( javascript ) SET vs UPDATECONTEXT
SET and UPDATECONTEXT both temporarily store data such as a line of text, a number, a date, a true/false value, etc.
SET creates a global variable which can be referenced on any screen. For example, you could create a variable called varFontSize and place it in the FontSize property of all the labels in your app. Then if you decide the text in your app needs to appear larger you could make the change by updating a single value. Set (varFontSize, 16 ) Code language: JavaScript ( javascript )
UPDATECONTEXT creates a local variable which can only be referenced from a single screen where it is initialized. What is the advantage of limiting a variable to a single-screen? Imagine that your app grows to have over 50 variables. It could become difficult keep track where all of those global variables are being used and also to troubleshoot any errors over multiple screens. Local variables are an excellent way to organize our code on a single screen keeping your app simple.
UpdateContext ({ locIsFormSubmitted : true}); Code language: CSS ( css )
At first it is difficult to understand when to use a global variable vs. a local variable. The best way to figure it out is through experimentation. IF vs SWITCH function
IF and SWITCH are both logical functions. They determine whether a series of conditions are true or false. Then based on the outcome a specific action is taken.
IF is the more well-known function in this pair. A benefit of the IF function is you can test multiple criteria at once as shown in the code below
If( varTestScore >= "80" And varTestScore <= 100 ,
Set (varGrade: "A" ), varTestScore > "70" And varTestScore < 80 ,
Set (varGrade: "B" ), varTestScore > "60" And varTestScore < 70 , Set (varGrade: "C" ), Set (varGrade: "F" ) ) Code language: JavaScript ( javascript )
SWITCH is much simpler by comparison. It can only test if a variable is equal to a defined value. Switch ( varNextScreen;
"Approved" , Navigate( 'Approved Screen' );
"Rejected" , Navigate( 'Rejected Screen' ); "Hold" , Navigate( 'Hold Screen' ); ) Code language: PHP ( php )
Why should you use SWITCH when considering the IF function does everything SWITCH can and more? Arguably, SWITCH is cleaner and more easily readable but in my opinion using it does not have any advantage in PowerApps. It is just another way of doing the same thing.
In other programming languages SWITCH can offer performance benefits. Pretend the code below was not written in PowerApps. The SWITCH function is more efficient because it only looks for the User’s name on the server only once. However, in Power Apps there is some behind-the-scenes magic that prevents multiple calls to the server in the same statement.
// Retrieves the username 3 times from the server, once for each comparison
If( User().FullName= "Jill" , Set (varRole: "General Manager" ), User().FullName= "Mark" , Set (varRole: "Supervisor" ) User().FullName= "Gerald" , Set (varRole: "Employee" ) ) // Only obtains the username once Switch( User().FullName,
"Jill" , Set (varRole: "General Manager" ), "Mark" , Set (varRole: "Supervisor" ), "Gerald" , Set (varRole: "Employee" ) ) Code language: JavaScript ( javascript ) TODAY vs NOW
TODAY and NOW each output information about the current date and time
TODAY only returns the date. You might not require any information about the time if you are checking whether it is a friend’s birthday. Today() >> Result: 7/3/2020
NOW shows both the date and the time. The time is important for scenarios like recording when a package was delivered Now() >> Result: 7/3/2020 9:36PM 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 or feedback about What’s The Difference Between These Power Apps Functions 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. COLORVALUE function CONCAT function CONCATENATE function IF function ISBLANK function ISEMPTY function Now function RGBA function SET function Switch function TODAY function UPDATECONTEXT function Matthew Devaney M365 Copilot Power Apps
How To Create Copilot Custom UI Widgets In Power Apps
Tagged
Power Apps
Have a Microsoft 365 topic idea?
Share article suggestions, community session ideas, corrections, or real-world scenarios for future nxtM365 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