Canvas Apps Expressions

Lookup users the right way in Power Apps!

Lookup users in Power Apps
Lookup users in Power Apps

The problem with LookUp

It is a pretty common use case to lookup users (using the LookUp function), especially the current logged in user, to get more details like their department or job title. Sometimes the function returns blank which is obviously incorrect. Let's look at why this happens and what the resolution is.

Problem happens when users have more than one email aliases. For example, if you want to send me an email to my Hitachi account:

  1. hbhatia@hsdyn.com
  2. hbhatia@hitachisolutions.com

The way to lookup a user is:

LookUp(
    Users,
    'Primary Email' = locUserPrincipalName
)

where locUserPrincipalName is

User().Email

or from a gallery for which the Items property is set to

Office365Users.SearchUser({searchTerm: txtTextInput_4.Text})
galUsers.Selected.UserPrincipalName

Fixing the issue

The way to fix this is to make sure you compare the email with both the user principal name and primary email. So modify the lookup function this way to make it work:

LookUp(
    Users,
    'Primary Email' = locUserPrincipalName || 'User Name' = locUserPrincipalName
)

Summary

In order to ensure that your user lookup works perfectly, make sure you compare the user's email (from the User() function or Office365Users.SearchUser() function) to both the 'User Principal' and 'Primary Email' fields of the Users table.

Recent articles

  1. Get rid of the back button in Power Apps studio!
  2. How to deep link into Teams from Power Apps
  3. How to create a Pinterest like gallery!

3 thoughts on “Lookup users the right way in Power Apps!”

  1. Navigating user lookups in Power Apps can initially seem complex, but this guide shines a light on the pathway, clarifying the differences between the Office 365 Users connector and Microsoft Dataverse. The inclusion of best practices and potential pitfalls, like delegation, is invaluable. As a reader, I feel equipped and empowered to handle user lookup scenarios with greater confidence and efficiency.

Leave a Reply