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 / Update Context variabl...
Power Apps
Unanswered

Update Context variable using If not working

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have a gallery with the "items" attribute set to a context variable, which is initially just a standard table. I'm trying to create a UI to filter the items on the gallery with two datepickers (which corresponds to the records' "desired settlement date" attribute) and three combo boxes (for three text attributes called "from", "to" and "status"). I initially tried both the combo boxes and datepickers individually to see if context variables could work for this and they did. I made a button with the word "filter" on it, and when you pressed it it would update the context variable. Testing out the datepickers, for example, I used this code for the button's on select attribute:

 

 

UpdateContext({contextVariable:Filter(TABLE, Desired_Settlement_Date >= dp_initial_date.SelectedDate, Desired_Settlement_Date <= dp_end_date.SelectedDate)})

 

 

and individually the datepickers and each combo box work fine using the code above.

 

However, I want to use combinations of those filtering options and not force the user to filter the records by desired settlement date if they only want to filter the records using the to and from attributes, for example. My initial thought was to do this: 

 

 

If(!IsEmpty(cb_to) && !IsEmpty(cb_from) && !IsEmpty(cb_status), UpdateContext({contextVariable:Filter(TABLE, Desired_Settlement_Date >= dp_initial_date.SelectedDate,Desired_Settlement_Date <= dp_end_date.SelectedDate, To.Value in cb_to.SelectedItems.Description, From.Value in cb_from.SelectedItems.Description, Status.Value in cb_status.SelectedItems.Description)}), 
IsEmpty(cb_to) && !IsEmpty(cb_from) && !IsEmpty(cb_status), ...

 

 

and basically checking every possible combination of which combo boxes were used to filter the records by the user (excluding the datepickers which are obligatory to use since I haven't figured out a way to avoid using them). I updated the above code using the same logic checking to see if different syntax would do the trick, but unfortunately I haven't found a way to make it work. I was wondering if anyone could point out my mistake or have more efficient code for doing this since 8 if conditions seems a bit much.

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

    HI @Anonymous ,

    Please consider using a Collection instead of a Variable for storing a Table and Patch the new values to it - if it does not work with that, I am happy to look at it for you.

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 April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 638

#2
Haque Profile Picture

Haque 317

#3
WarrenBelz Profile Picture

WarrenBelz 315 Most Valuable Professional

Last 30 days Overall leaderboard