What’s The Difference Between These Power Apps Functions?
“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:
|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)), )
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)
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.
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"))
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];
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
What if the emails were stored in a table like this instead?
Employees (SharePoint List)
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];
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.
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.
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") )
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'); )
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") )
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 Power Apps articles sent to your inbox each week for FREE
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.