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

16 REPLIES 16
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

 

hey there if you liked the post give it a thumbs up, and if it solved your question please accept it as a solution.
mgs78
Regular Visitor

Hi @rubin_boer 

Thanks for your input - I have some trouble figuring out step 2

 

My code look like this:

ClearCollect(colFiltered,
Switch(true,
ThisItem.id = 1, Filter('SP-VEDLTasks', Status.Value = ThisItem.name),
ThisItem.id = 4, 'SP-VEDLTasks' //same as your all tasks
)
); Navigate(AllTasks,None)

 

ThisItem.Id = 4 works just fine, but ThisItem.id = 1 I can not make it work. Can you elaborate a little more?

rubin_boer
Super User
Super User

hi @mgs78 im glad to see id = 4 works, well done. ThisItem.name will be the "view new tasks", what is the value which you wish the evaluated Status.Value to? you may ant to change that to the value you wish to filter that column. 

hey there if you liked the post give it a thumbs up, and if it solved your question please accept it as a solution.

hi @rubin_boer 

 

The reason why it was not working was because I didn't use the colFiltered on the gallery.

My codes look like this:

ClearCollect(colFiltered,
Switch(true,

ThisItem.id = 1, Filter('SP-VEDLTasks', Status.Value= ThisItem.name),
ThisItem.id = 2, Filter('SP-VEDLTasks', 'Assigned To'.Email= User().Email),
ThisItem.id = 3, Filter('SP-VEDLTasks', 'Reported By'.Email=User().Email),
ThisItem.id = 4, 'SP-VEDLTasks' //same as your all tasks
)
); Navigate(AllTasks,None)

 

2 issues left: search text field on 2nd screen and button 1

mgs78
Regular Visitor

Hi @rubin_boer 

I think I can call this for done now.

ClearCollect(colFiltered,
    Switch(true,
        ThisItem.id = 1, Filter('SP-VEDLTasks', Status.Value= ThisItem.name),
        ThisItem.id = 2, Filter('SP-VEDLTasks', 'Assigned To'.Email= User().Email),
        ThisItem.id = 3, Filter('SP-VEDLTasks', 'Reported By'.Email=User().Email),
        ThisItem.id = 4, 'SP-VEDLTasks',
        ThisItem.id = 0, NewItemScreen
    )
); If(ThisItem.id <> 0, Navigate(AllTasks,None)) || If(ThisItem.id = 0, Navigate(NewItemScreen,None))

 Can you help me with my search issue in  this tread or is it best for me to create a new post?

rubin_boer
Super User
Super User

@mgs78 im glad you sorted yip I think let's do search separately. 

hey there if you liked the post give it a thumbs up, and if it solved your question please accept it as a solution.
D_Izani
Regular Visitor

Hello @mgs78 have you able to solve your problem cause right now, I face the same issue.

 

1. Here is my Screen 1

D_Izani_0-1658648748700.png

 

2. Here is my Gallery on the 2nd screen but I can't filter the list according to a category on screen 1

D_Izani_1-1658648841242.png

 

What is the best coding cause right now I used this on Gallery:

Sort(
       Filter(
            'Inventory Management',
             Category = "Office"
          )         
)

 

and all the list will not come out. Hope you can help me. Thank you!

Helpful resources

Announcements
Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Government Carousel

New forum: GCC, GCCH, DoD - Federal App Makers (FAM)

In response to the unique and evolving requirements of the United States public sector, Microsoft has created Power Apps US Government.

Users online (2,224)