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 / How to filter the resu...
Power Apps
Answered

How to filter the results of a dropdown based on an IF statement and the results of another dropdown

(0) ShareShare
ReportReport
Posted on by 106

Hello,

 

We are populating the Items of a dropdown box with the calculation below.  This works fine.

 

Sort(Distinct(Filter('MyLookup', LookupType=LookupType.Selected.LookupTypeName), FinalName),Result,Ascending)
But, we would like the filter logic to be different based on the value in the LookupType dropdown:
LookupType=LookupType.Selected.LookupTypeName
i.e. If (LookupType.Selected.LookupTypeName="x" Filter by "x" 
ELSE If LookupType.Selected.LookupTypeName="y" then do not apply ANY filter - show everything.

I've tried various methods of doing this but none have worked.
Any help appreciated.

Thanks,
Dan
Categories:
I have the same question (0)
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Hi @lesotho_kid 

    Rather than get down in the weeds and work thought the logic, I like use UpdateContext() to create a variable as an alias for the function.  so 

     

     

    UpdateContext({varA: ComplexformulaA});UpdateContext({varB: ComplexformulaB})

     

     

    in the Items propery of the gallery or datatable: If(conditionA, varA, varB) 

  • lesotho_kid Profile Picture
    106 on at

    Thanks @Drrickryp 

    That helps a gives a different way of looking at the problem.  Helps with several other calcs also since that field is frequently used.

    One follow-up question.  Where would I put the UpdateContext code?  In the 'OnChange' event of the dropdown box which all these formulas are referencing?

     

    Thanks Again!

    Dan

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

    Hi @lesotho_kid 

    I would use a button or icon but you could use the onchange of the dropdown.  You would need to put the context variable that you choose for a default in the OnVisible property of the screen containing the dropdown so the gallery wasn't blank when the screen opens. Another way to do it if you have several different formulas is to use a Radio control with the labels as the different filters. 

  • lesotho_kid Profile Picture
    106 on at

    Thanks @Drrickryp !  Appreciate your help with this.

     

    Thanks,

    Dan

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Just a quick note since you mentioned that you may be using the variable in other places in your app.  In that case, I would use the Set() function instead of the UpdateContext() function.  The Set() function creates a global variable that will be available throughout all the screens in your app until you change it.  UpdateContext() only applies to the active screen. The syntax for the Set() function is very similar to UpdateContext() except it doesn't use curly braces and has a comma instead of a colon.  So Set(var,Formula) instead of UpdateContext({var:Formula})

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 387

#2
timl Profile Picture

timl 340 Super User 2026 Season 1

#3
Vish WR Profile Picture

Vish WR 301

Last 30 days Overall leaderboard