web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Using Switch() with Of...
Power Apps
Answered

Using Switch() with Office365Users.UserPhotoV2()

(0) ShareShare
ReportReport
Posted on by

I have a canvas app and I'd like to display a user's photo based on value in a collection, ideally using Switch()

 

For example: If the collection contains "EmployeeID1234," show the photo for Silvia. If the collection contains "EmployeeID5678," show the photo for Ernest, etc.

 

I can use this to display a user's photo based on their email address:

// Image Property
Office365Users.UserPhotoV2("silvia@example.com")

But I'd like to change the photo in the Image control based on the "EmployeeID" field in my collection. Something like this (which isn't working):

With({
wPhoto: LookUp(colMyCollection, ThisRecord.EmployeeID = Switch(EmployeeID,
"EmployeeID1234", Office365Users.UserPhotoV2("silvia@example.com"), // Show Silvia's photo
"EmployeeID5678", Office365Users.UserPhotoV2("ernest@example.com"), // Show Ernest's photo
"EmployeeID9112", Office365Users.UserPhotoV2("oscar@example.com") // Show Oscar's photo
))
},
If(!IsBlank(wPhoto), wPhoto, 'no-profile-photo')
)

If the user doesn't have a profile photo, I'd like to show my default image called "no-profile-photo."

 

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    156,386 Most Valuable Professional on at

    Hi @Siddz ,

    Try this way

    With(
     {
     wPhoto: 
     LookUp(
     colMyCollection,
     EmployeeID = 
     Switch(
     ThisItem.EmployeeID,
     "EmployeeID1234",
     "silvia@example.com",
     "EmployeeID5678",
     "ernest@example.com",
     "EmployeeID9112",
     "oscar@example.com"
     )
     )
     },
     If(
     !IsBlank(wPhoto),
     Office365Users.UserPhotoV2("wPhoto"),
     'no-profile-photo'
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • Siddz Profile Picture
    on at

    Thanks, @WarrenBelz.

     

    That makes sense to move Office365Users.UserPhotoV2() to the IF-condition, but the LookUp() is not returning a match for some reason, so only the fallback photos show ('no-profile-photo').

     

    Siddz_0-1673216942244.png

     

    My Image control is not in a gallery, but I tried using the code above in a gallery as well with the same result (only the fallback photos were displayed).

     

    The users in my example have a photo associated with their profiles because these return photos:

    Office365Users.UserPhotoV2("silvia@example.com") // Image control
    Office365Users.UserPhotoV2("ernest@example.com") // Image control

     

  • Verified answer
    WarrenBelz Profile Picture
    156,386 Most Valuable Professional on at

    Hi @Siddz ,

    My first attempt was more on structure without really looking at the logic - but now the logic has be a bit confused - why are you looking up the collection at all when you are hard-coding the email based on the EmployeeID in the current record - logic as I see your current code probably should be

    With(
     {
     wID: 
     LookUp(
     colMyCollection,
     EmployeeID = ThisRecord.EmployeeID
     ).EmployeeID
     },
     With(
     {
     wMail: 
     Switch(
     wID,
     "EmployeeID1234",
     "silvia@example.com",
     "EmployeeID5678",
     "ernest@example.com",
     "EmployeeID9112",
     "oscar@example.com"
     )
     },
     If(
     !IsBlank(wMail),
     Office365Users.UserPhotoV2(wMail),
     'no-profile-photo'
     )
     )
     )
    )

    but why not simply

    With(
     {
     wMail: 
     Switch(
     ThisRecord.EmployeeID,
     "EmployeeID1234",
     "silvia@example.com",
     "EmployeeID5678",
     "ernest@example.com",
     "EmployeeID9112",
     "oscar@example.com"
     )
     },
     If(
     !IsBlank(wMail),
     Office365Users.UserPhotoV2(wMail),
     'no-profile-photo'
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

     

     

  • Siddz Profile Picture
    on at

    Thanks, @WarrenBelz!

     

    I now have a working solution based on your help.

     

    I'm using a LookUp() on the collection because I want to display a user's photo based on the EmployeeID field. Essentially, I'm using a single image control and changing the photo each time depending on the EmployeeID. The collection name is always the same (colMyCollection), but the content of the collection is determined by a filter.

     

    For example, on the previous screen, if a user clicks "Team A," colMyCollection will be filtered to contain only employees from Team A. The logic of my Image control is: If the collection contains EmployeeID "1234," show the photo for "silvia@example.com." If the collection contains EmployeeID "5678," show the photo for "ernest@example.com." 

     

    Here's my working solution. My hunch is there's a more concise way to write this, though.

     

    With(
    {
    wID: LookUp(
    colMyCollection,
    EmployeeID = "1234" || EmployeeID = "5678" || EmployeeID = "9112"
    ).EmployeeID
    },
    With(
    {
    wMail: Switch(
    wID,
    "1234",
    "silvia@example.com",
    "5678",
    "ernest@example.com",
    "9112",
    "oscar@example.com"
    )
    },
    If(
    !IsBlank(wMail),
    Office365Users.UserPhotoV2(wMail),
    'no-profile-photo'
    )
    )
    )

     

  • WarrenBelz Profile Picture
    156,386 Most Valuable Professional on at

    Hi @Siddz ,

    As I noted, I cannot see your data, but assumed the value you wanted to compare with was ThisRecord.EmployeeID and stuck with that, but based on what you have posted, the top filter is just returning the value you put into it (actually the first matching item in the collection to your hard-coded values) - so I am a little confused as to what you are actually doing here.

  • Siddz Profile Picture
    on at

    Hi, @WarrenBelz.

     

    Sorry about that. Your solution works. I meant that my modification may not be concise (because I added the OR operators).

     

    You're right. I want to display a photo based on ThisRecord.EmployeeID

     

    I'd like the same Image control to be shared by several employees across different teams, so the photo that displays depends on how the collection is filtered. If "Team B" is loaded into colMyCollection, the photo for "ernest@example.com" should display. If the user chooses "Team C," which will ClearCollect and load "Team C," the photo for "oscar@example.com" should be displayed. 

     

    Since all EmployeeIDs are unique, I'm returning the first matching item in the collection. I'm using a Switch() because I don't know which team the user will load into the collection, but if they, for example, choose "Team A," I'll know to display Silvia's photo because Silva's EmployeeID is part of the Switch().

     

    This is a bit of a convoluted scenario. Appreciate your input!

  • WarrenBelz Profile Picture
    156,386 Most Valuable Professional on at

    Hi @Siddz ,

    So we can close this now ?

  • Siddz Profile Picture
    on at

    Hi, @WarrenBelz.

     

    I accepted the solution. Thanks again.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 401 Most Valuable Professional

#2
11manish Profile Picture

11manish 201 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard