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 / If statement inside lo...
Power Apps
Answered

If statement inside lookup statement

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi

I am trying to add an if statement inside lookup. I want it so that "onSelect" if approved equals no change to yes; and if approved equals yes change to no. 

 

 

Patch(Expense, (LookUp(Expense, Approved="No")), ({Approved:"Yes"}));

 

 

 

Categories:
I have the same question (0)
  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hi @Anonymous 

     

    Can you please share more details about the configuration of the app? I want to understand the controls used.

     

    If you are looking to update all records where the value is Approved, then you need to use the UpdateIf function:

     

    UpdateIf(Expense, Approved="No", {Approved:"Yes"});

     

     

    UpdateIf(Expense, Approved="Yes", {Approved:"No"});

     

     

    If you are just looking for one item, then use the below expressions:

    Patch(Expense, LookUp(Expense, ColumnToMatch="ValuetoMatch"), {Approved: If(LookUp(Expense, ColumnToMatch="ValuetoMatch").Approved = "Yes","No","Yes")})

     

     

    Hope this Helps!

     

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered 

     

     

    questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

  • eka24 Profile Picture
    20,925 on at

    What datasource are you using?

    If the Approved Column is a simple text column;

    UpdateIf(Expense,
        Approved=”Yes”,{Approved: “No”},
       Approved =”No”, { Approved: “Yes”})

     

    However if its a YesNo Column:

    UpdateIf(Expense,

        Approved =true, { Approved: 0},

        Approved =false,{Approved: 1})

    ------------

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi 

    Thanks for replying. The app is an expense app when you click on the "Approved" or "Not approved" button for an expense it will change to the opposite e.g. you click on "Approved" it will change to "Not approved".

     

    de97_1-1611064727079.png

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I dont want all approved expenses to change from "Yes" to "No". Just the one selected I tried using This.Approved = "Yes" but it does not work

  • Verified answer
    yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    @Anonymous 

     

    In that case, you can set the expression to:

     

    UpdateIf(Expense, ID = GalleryName.Selected.ID, {Approved: If(Gallery.Selected.Approved = "Yes","No","Yes")})

    OR

    UpdateIf(Expense, ID = ThisItem.ID, {Approved: If(ThisItem.Approved = "Yes","No","Yes")})

     

     

    Hope this Helps!

     

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    At the moment in my excel file I do not have column called "ID" could I use "PowerAppsId" column? or would I have to create another column called "ID" 

    de97_0-1611068201138.png

     

  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @Anonymous 

    All tables in a database should have a Unique ID column that is never changed once it is assigned and is not reused.  It can be a whole number (preferred) or a string and it is called the Primary Key of the table.   The PowerAppsID column is for internal use only and can is not exposed within PowerApps so the answer to your question would be no.  For more information about database keys and why we use them see my blog post here: https://powerusers.microsoft.com/t5/News-Announcements/Relational-Database-Principles-and-PowerApps-Step-3-Keys-and/ba-p/188640 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 510

#2
WarrenBelz Profile Picture

WarrenBelz 426 Most Valuable Professional

#3
Vish WR Profile Picture

Vish WR 281

Last 30 days Overall leaderboard