PowerApps (LookUp an Item)
For those of you that were around before smartphones and the internet were a thing, I am sure you remember the thick phonebooks that were delivered to our door steps. I remember thumbing through the yellow or white pages looking for a name to get a phone number or address. Those days were fun (sarcasm).
In this blog post I will be going over what the LookUp function is in PowerApps and how to use it. The LookUp function is one that every PowerApps developer should know how to use and when to use it. Luckily, the LookUp function is not as painful as using the antiquated phonebook.
According to the Microsoft Documentation, the LookUp function looks for the first record in a data source that satisfies a condition which returns a boolean. An example will help to illustrate this. Let’s say I have a SharePoint list with several items (can also be considered records) and they contain information about all the fast food places in the area (McDonald, Subway, Wendy’s, etc.). If I use the LookUp function, it would retrieve the first ‘Subway’ in the SharePoint list regardless of how many Subway locations are in the list. Here’s my ‘Fast Food’ list
Fast Food | |
---|---|
Name | Street |
McDonald | 7th st |
Subway | ABC Avenue |
Wendy’s | 11th St |
Subway | 9th St |
Hardee’s | Kinte St |
Here’s how to use the LookUp function to perform the same ‘Subway’ search in PowerApps.
The LookUp function has 3 parameters. The first 2 are required and the last is optional.
LookUp(datasource, formula, reduction formula)
Example:
LookUp('Fast Food',Name="Subway",Street)
returns
‘ABC Avenue‘
LookUp(datasource, formula)
returns
Subway | ABC Avenue |
When the optional parameter is used, just a single value from the record is returned. When the optional parameter is not used, the whole record or item is returned.
Here’s a practical use of the LookUp function. Let’s say you have an application that requires Admin access to parts that a regular user shouldn’t have access to. You can have an access control list, which has a list of Admin users.
Admin | Access |
---|---|
John Doe | Manager |
Sue Doe | CTO |
Bobby Lou | Director |
If in your app, you wanted only the Sue Doe, CTO, to see certain information. You can use a LookUp to find Sue Doe. Here’s how:
LookUp(Admins, Admin = "Sue Doe")
The above translates to, look in the Admin list where the Admin column is equal to “Sue Doe”.
I hope this is helpful.
Happy PowerApping!!!
Power Platform PowerApps SharePoint SharePoint Online LookUp function Power Apps PowerApps SharePoint Online