cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Powerman1
Level: Powered On

Filter Galleries

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)

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Filter Galleries

@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.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

6 REPLIES 6
Community Support Team
Community Support Team

Re: Filter Galleries

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

 

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Powerman1
Level: Powered On

Re: Filter Galleries

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.

Super User
Super User

Re: Filter Galleries

@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.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

TimRohr
Level 10

Re: Filter Galleries

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.

Super User
Super User

Re: Filter Galleries

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.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Powerman1
Level: Powered On

Re: Filter Galleries

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.

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

Top Kudoed Authors
Users Online
Currently online: 295 members 6,329 guests
Please welcome our newest community members: