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 Apps
Answered

Filter Galleries

(0) ShareShare
ReportReport
Posted on by 40

Hi everyone.

 

I am having troubles filtering a gallery using buttons.

 

Info: Using a powerapp to track faults in a sharepoint list.

 

Basically have it so items in a list become resolved once a date has been entered in the Date Resolved field. Otherwise it is open.

 

What I'm trying to do:

Button: Open Faults - Any faults with Date Resolved being empty.

Button: Resolved - Faults with Date Resolved with date entered.

Button: All - Display all.

 

 

So far I've tried but no such luck.

Filter('Fault Register', 'Date Resolved'=IsBlank('Date Resolved'))

 

SortByColumns(Filter('Fault Register',!IsBlank('Date Resolved')),'Date Resolved',Ascending)

Categories:
I have the same question (0)
  • v-yamao-msft Profile Picture
    on at

    Hi @Powerman1 ,

     

    Do you want to show different items on the gallery by clicking corresponding buttons?

    Please take the following steps for a reference.

    There is a date time column named as DateChange in the list.

    Create a connection to the list.

    Add a gallery control, and three buttons above the gallery. Change the text of the button separately to OpenFaults, Resolved, All.

    Then OpenFaults.OnSelect with the following code:

    ClearCollect(newlist11,Filter(List11,IsBlank(DateChange)))

    Set Resolved.OnSelect with the following code:

    ClearCollect(newlist11,Filter(List11,Not(IsBlank(DateChange))))

    Set All.OnSelect property with the following function:

    ClearCollect(newlist11,List11)

    Then set the Items property of the Gallery as:

    newlist11

    1.PNG

     

    Best regards,

    Mabel

     

  • Powerman1 Profile Picture
    40 on at

    Hi,

     

    This works brilliantly, however I am also trying to filter the gallery to show the most recent created by using the created field.

     

    SortByColumns('Fault Register',"Created",Descending);

     

    I tried adding

     

    ClearCollect('newFault Register','Fault Register');SortByColumns('Fault Register',"Created",Descending) but no affect.

     

    Thanks for your help on this.

  • Verified answer
    RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @Powerman1 

    You might want to go a slightly simpler way rather than creating Collection for the gallery.

     

    Here in this example, you will have the three buttons and in the OnSelect formulas for them you will have the following:

      All.OnSelect - UpdateContext({_filter:"All"})

      Resolved.OnSelect - UpdateContext({_filter:"Resolved"})

      Open.OnSelect - UpdateContext({_filter:"Open"})

     

    Then on your Gallery Items the following:

       Filter('Fault Register', (IsBlank('Date Resolved') && _filter="Open") || (!IsBlank('Date Resolved') && _filter="Resolved") || (_filter="All"))

     

    To add sorting to this, adjust to the following:

       SortByColumns(Filter('Fault Register', (IsBlank('Date Resolved') && _filter="Open") || (!IsBlank('Date Resolved') && _filter="Resolved") || (_filter="All")), "Created", Descending)

     

    The above will give you a formula that will use the condition value of the variable _filter to determine what logic to apply to the Filter condition.  

     

    Hope this helps some.

  • TimRohr Profile Picture
    669 on at

    I prefer to not use Collections for the source of a Gallery unless I have to. If your list runs over 500 items (with sundry caveats), you're going to have to run your Collect() statement a number of times. Not to mention you're then working with a copy of your data, not the actual underlying table.

     

    You could set up the Gallery to have an Items property built using an If() statement...

     

    If (
     Condition1, Filter(....),
     Condition2, Filter(....),
     Condition3, yourUnfilteredSource
    )

    Then use your buttons' OnSelect property to establish whatever that condition you want to use:

     

    ...a string that is one of 3 values for your three cases

    ...a set of 3 boolean values, where each button only sets one to be true and the rest to be false

    And feed that condition test into the If() statement:

    If (
     yourString = "Faults", Filter(.....),
     yourString = "Resolved", Filter(.....),
     yourString = "All", yourUnfilteredSource
    )

     

     

    Now, to address your Sorting requirement, if you always want the Gallery to be sorted, you have to wrap the statement producing the table of Items in a SortByColumns() statement. In @v-yamao-msft 's suggestion, that would be:

     

    SortByColumns(newList11, "Created", Descending)

    ...But you can wrap my If() statement in the same SortByColumns() to arrive at the same place:

     

    SortByColumns(
     If (
     yourString = "Faults", Filter(.....),
     yourString = "Resolved", Filter(.....),
     yourString = "All", yourUnfilteredSource
     ),
     "Created",
     Descending
    )

    On the other hand, if you wanted to turn the sorting on/off, then you could either have another If() statement wrapping the whole statement, with one branch incorporating the SortByColumns() verbiage and other branch no, or you could embed an If() statement into the field selection for the SortByColumns() statement, provided you could supply what field should provide the default sorting.

    For example, imagine you had a field in your datasource called "Assigned", and you added a checkbox to your screen that was labeled "Sort by Assigned" and named chkSortByAssigned. Typically you wanted to sort on Created, but when you checked the box, you wanted to sort on Assigned. That Items statement would look like:

    SortByColumns(
     If (
     yourString = "Faults", Filter(.....),
     yourString = "Resolved", Filter(.....),
     yourString = "All", yourUnfilteredSource
     ),
     If ( chkSortByAssigned,
     "Assigned",
     "Created"
     )
     Descending
    )

    Some people might find that more dense to parse out what is going on, but I find it more helpful to have all of my code language right there in the one place, especially if it gets me the added benefits I listed, above.

  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    I prefer the shorter formula version I posted, but the post by @TimRohr will work equally well and, as he mentioned, if you can avoid creating collections for these things, unless absolutely necessary, you are better off.

  • Powerman1 Profile Picture
    40 on at

    This worked perfectly, exactly what I was trying to do. Thank for your help. I will look through the alternative as well to learn more.

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 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard