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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Set Variable based on ...
Power Apps
Unanswered

Set Variable based on Lookup

(0) ShareShare
ReportReport
Posted on by 55

Hello,

I feel like this should be easy, but it's not working. I have a Sharepoint list with email addresses as the title, and then an option field that is "A" "B" or "C". 

Within PowerApps, I want to set a different variable OnStart based on looking up which option (A, B, or C) coincides with that user's email address. 

I was trying this, but it wasn't working. Any other ideas on a better way to do this?

 

If(LookUp('Sharepoint', User().Email=Title).Option="A",Set(varA,true));
If(LookUp('Sharepoint', User().Email=Title).Option="B",Set(varB,true));
If(LookUp('Sharepoint', User().Email=Title).Option="C",Set(varC,true));

 

 Thanks!

Categories:
I have the same question (0)
  • Ismael_Novo Profile Picture
    308 on at

    Hi dsopshin!

     

    The issue in your code is that the Set function in Power Apps is not used within If conditions. Instead, it is used separately, and the If conditions should be used to determine the values to be set:

     

    Set(varA, LookUp('Sharepoint', User().Email = Title).Option = "A");
    Set(varB, LookUp('Sharepoint', User().Email = Title).Option = "B");
    Set(varC, LookUp('Sharepoint', User().Email = Title).Option = "C");

     

    Go on!

  • WarrenBelz Profile Picture
    153,026 Most Valuable Professional on at

    Hi @dsopshin ,

    The proposal from @Ismael_Novo is a far better structure, but they both should work (there is nothing wrong with setting different Variables conditionally). You could also do this

    With(
     {
     wOption:
     LookUp(
     'Sharepoint', 
     User().Email = Title
     ).Option
     }, 
     Switch(
     wOption,
     "A",
     Set(varA,true),
     "B",
     Set(varA,true),
     "C",
     Set(varC,true)
     )
    )

    My main suggestion here is why not simply have one Variable set to the option

    Set(
     varOption,
     LookUp(
     'Sharepoint', 
     User().Email = Title
     ).Option
    )

    then if you want a true/false result for something, you just need (example)

    varOption = "A"

    which will return true or false the same as varA you have )and saves two variables from your total).

     

    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

     

     

     

  • developerAJ Profile Picture
    4,628 on at

    i would recommend warren main suggestion

     

     i could see you mentioned like this  then an option field that is "A" "B" or "C". 

    if its choice column than

    Set(
     varOption,
     LookUp(
     'Sharepoint', 
     User().Email = Title,Option.Value
     )
    )
  • Verified answer
    WarrenBelz Profile Picture
    153,026 Most Valuable Professional on at

    @dsopshin ,

    I did not read your post well enough - a Lookup columns needs .Value in the reference.

    With(
     {
     wOption:
     LookUp(
     'Sharepoint', 
     User().Email = Title
     ).Option.Value
     }, 
     Switch(
     wOption,
     "A",
     Set(varA,true),
     "B",
     Set(varA,true),
     "C",
     Set(varC,true)
     )
    )

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard