cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mgs78
Regular Visitor

Filtering gallery by variables

Hi

 

I’m new to building PowerApps and programming. So, I hope there is a patient person there can help me with applying a filter to my gallery.

 

My app is created against SharePoint list.

 

I have 2 screens in my app.

 

Screen 1 – is the start screen with 4 buttons.  Each button navigates to the same gallery  on screen 2, but with a unique value. (“varStatus”, “varAssignTo” and “varReportedBy”) The 4th and last button navigates to the gallery and have to show “All issues”

I have tried to build a filter, but with no luck.

 

I can someone give me some pointers/directions on how to solve my filter issue?

Br

1 ACCEPTED SOLUTION

Accepted Solutions
rubin_boer
Super User
Super User

@mgs78 cool

 

looking at your buttons you can add those to a gallery with the following table which will make things a bit easier.

 

Step 1 - create buttons in gallery

add a gallery and set the Items to the code

Table(
    {id:0, name: "Create new task"},
    {id:1, name: "View new task"},
    {id:2, name: "My tasks"},
    {id:3, name: "All task"},
    {id:4, name: "Reported ny me"}
)

 

Add a button to the gallery and set the text = Thisitem.name //name is not something i use so just to illustrate the functionality 😉

 

Result

rubin_boer_0-1656442127085.png

 

Now we have buttons, lets do something with them

I will create a datasource for illustration as below (this will be your datasource in your case)

ClearCollect(
    someDataToAbuse,
    ForAll(
        Sequence(20),
        {
            id:Value,
            name:"name: " & Mod(Value,3),
            status:Mod(Value,5) = 0,
            assignedTo:If(Mod(Value,4) = 0,"me","someone else")
        }
    )
)

 

Result

rubin_boer_1-1656442307786.png

 

Step 2 

when i click on new task i want to see all the all records with the name = "name: 0" //same as you want to filter a column with a specific text

my tasks, i want to see all the assignedTo = "me"

all tasks, i want to see everything.

 

to get to this select the OnSelect of the gallery that you created for the buttons in step 1.

we going to create a filtered collection and assign that you you gallery, this will be the gallery on your second screen.

ClearCollect(colFiltered,
    Switch(true,
        ThisItem.id = 1, Filter(someDataToAbuse, name = "name: 0"), //same as your new task for example
        ThisItem.id = 2, Filter(someDataToAbuse, assignedTo = "me"), //same as your my tasks for example
        ThisItem.id = 3, someDataToAbuse //same as your all tasks
    )
);
//navigate to your screen will go here

 

Result

Peek 2022-06-28 20-56.gif

 

You can can add function to the OnSelect for "create new task" and "re[ported by me" by using the id.

 

Hope it helps,

R

 

View solution in original post

16 REPLIES 16
AJ_vizMan
Helper V
Helper V

Hi @mgs78 - there is similar query answered. Take a look :

Solved: How to display a column within a PowerApps Gallery... - Power Platform Community (microsoft....

If, it's different from what you need to solve than share below info : What does "All Issues" refer - All the columns or just single column? Data type of column to filter?

mgs78
Regular Visitor

Thanks for your reply but I think it is too advanced for what I want.

 

I have attached screenshots of my app which I hope can help explain what I mean.
When I click on the "View new tasks" button on screen 1, the user must navigate to screen 2 and the gallery must be filtered so it is only items with status "New" there are displayed.

AJ_vizMan
Helper V
Helper V

@mgs78  - Now, i could understood your query much better, thanks for screenshots.

You can achieve the gallery filtration using variables. 

Steps :

1. Define a filter variable at 'On Start' of app 
Set(Filtervar, Blank())

2. Now, go to the button and on 'On Select' property

Navigate(Screen1_1); // Screen to navigate 

Set(Filtervar,"Title1") // Set the filter var e.g. "New" (if you are filtering using Status)
3. Change Items property of Gallery - 
Filter(
SharePointListName,
ColumntoFilter = Blank() Or ColumntoFilter = Filtervar) 

PS : you can use Or function to filter out using multiple columns.

In my case, i defined filtervar on 'On Start' of app
than on Screen 1 - on select property of Button

AJ_vizMan_0-1656424930953.png

 

Than 'Items' property of gallery on next screen

AJ_vizMan_1-1656425033310.png

i hope this helps. 

mgs78
Regular Visitor

Hi AJ_vizMan

I'm (we) almost there 🙂

I have set the APP OnStart to Set(varStatus, Blank()); Set(varAssignTo, Blank()); Set(varReportedBy, Blank())

I have set the buttons to:

Button 1: Set(varStatus, "Not started"); Navigate(AllTasks,None)

Button 2: Set(varAssignTo, User().Email); Navigate(AllTasks,None)

Button 3: Set(varReportedBy, User().Email); Navigate(AllTasks,None)

 

And I have made the gallery filter as this: 

SortByColumns(Filter('SP-VEDLTasks', Status.Value = varStatus Or 'Reported By'.Email=varReportedBy Or 'Assigned To'.Email=varAssignTo),"ID", Descending)

 

BUT I'm not getting the expected result - there are to many records. Can you see want I have done wrong?

uwenagel
Resolver II
Resolver II

Hi @mgs78

 

I would solve this with a collection that is filled depending on the button you pressed:

 

Button1: Set(varStatus, "Not started"); ClearCollect(myCollection,SortByColumns(Filter('SP-VEDLTasks', Status.Value = varStatus),"ID", Descending); Navigate(AllTasks,None)

Button2: Set(varReportedBy, User().Email); ClearCollect(myCollection,SortByColumns(Filter('SP-VEDLTasks', 'Reported By'.Email=varReportedBy),"ID", Descending); Navigate(AllTasks,None)

Button3: Set(varAssignTo, User().Email); ClearCollect(myCollection,SortByColumns(Filter('SP-VEDLTasks', 'Assigned To'.Email=varAssignTo),"ID", Descending); Navigate(AllTasks,None)

 

Then in the AllTasks screen you can set your gallery's items to myCollection.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item.

If the content was useful in other ways, please consider giving it Thumbs Up.

mgs78
Regular Visitor

Hi @uwenagel 

I have not worked with Collection before - can you help me define the collection and be mere specific on how to write code at gallery?

mgs78
Regular Visitor

Hi @uwenagel 

I figured out how to use the collection, but it leave me with 2 other issues.
1. How to make button that show all items in the gallery. 

2. How to make search (StartsWith...) field on the screen with the gallery

 

Can you also help me with these challenges?

rubin_boer
Super User
Super User

hi @mgs78 you have been exposed to a few options, do you mind another one?

Hi @rubin_boer 

No - it is nice to have some options to choose between 🙂

 

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (3,271)