cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ppl
Post Patron
Post Patron

Filter by value

Hello!

 

I am trying to make filter function in my app.

It was build from default template and in BrowseScreen it has a Gallery with Items field as:

SortByColumns(Filter([@'Facility Desk'], StartsWith(Title, TextSearchBox1.Text)), "Created", If(SortDescending1, Descending, Ascending))

 

In my SharePoint list I have such fields as Responsible and Plant. Responsible is a person and Plant is a choice field where we can choose one of two plants.

 

I want to make a buttons which will filter items in my list by Plant. If I press Plant 1 button it must show items only with Plant1 value

and the same with plant2

Annotation 2020-05-16 210455.png

Annotation 2020-05-16 210528.png

 

And when I press Not assigned button it will show items only with Status = New

Annotation 2020-05-16 210544.png

 

And the last is Assigned to me button which will show only items which Responsible email field equals Email of user who is logged in.

Annotation 2020-05-16 210641.png

 

I wrote functions like this, but they are not working.

 

1 ACCEPTED SOLUTION

Accepted Solutions
KrishnaV
Community Champion
Community Champion

Hi @ppl ,

 

As we know in PowerApp filtering on choice work little different please find the below formula you need to set for the gallery items property:

If(varMyValue,
If(
    IsBlank(varStatusValue),
    Filter(
        'Employee Details',
        varPlantValue in Plant.Value And Responsible.Email = varUser.mail)
    ,
    Filter(
        'Employee Details',
        (varPlantValue in Plant.Value And varStatusValue in Status.Value And Responsible.Email = varUser.mail)
    )
),
If(
    IsBlank(varStatusValue),
    Filter(
        'Employee Details',
        varPlantValue in Plant.Value )
    ,
    Filter(
        'Employee Details',
        (varPlantValue in Plant.Value And varStatusValue in Status.Value )
    )
)
)

In the above code block, var user is a global user and I am getting user profile as below:

Set(varUser,Office365Users.MyProfileV2());

This is at the app OnStart property.

On plant1 onSelect property:

UpdateContext({varPlantValue:"Plant 1"});

on Plant2 onSelect:

UpdateContext({varPlantValue:"Plant 2"});

On Not assigned OnSelect:

UpdateContext({varStatusValue:"New"});

On EveryStatus OnSelect:

UpdateContext({varStatusValue:""});

 On Assigned to me OnSelect:

UpdateContext({varMyValue:true});

On All Users on Select:

UpdateContext({varMyValue:false});

That will work as below:

Choice Values.gif

 

Please let me know if you see any issue, I am always happy to help.

 

Regards,

Krishna

If you see this reply helped Mark it as the solution and give a thumbs-up. 

 



I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a THUMS-UP and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.

View solution in original post

3 REPLIES 3
KrishnaV
Community Champion
Community Champion

Hi @ppl ,

 

As we know in PowerApp filtering on choice work little different please find the below formula you need to set for the gallery items property:

If(varMyValue,
If(
    IsBlank(varStatusValue),
    Filter(
        'Employee Details',
        varPlantValue in Plant.Value And Responsible.Email = varUser.mail)
    ,
    Filter(
        'Employee Details',
        (varPlantValue in Plant.Value And varStatusValue in Status.Value And Responsible.Email = varUser.mail)
    )
),
If(
    IsBlank(varStatusValue),
    Filter(
        'Employee Details',
        varPlantValue in Plant.Value )
    ,
    Filter(
        'Employee Details',
        (varPlantValue in Plant.Value And varStatusValue in Status.Value )
    )
)
)

In the above code block, var user is a global user and I am getting user profile as below:

Set(varUser,Office365Users.MyProfileV2());

This is at the app OnStart property.

On plant1 onSelect property:

UpdateContext({varPlantValue:"Plant 1"});

on Plant2 onSelect:

UpdateContext({varPlantValue:"Plant 2"});

On Not assigned OnSelect:

UpdateContext({varStatusValue:"New"});

On EveryStatus OnSelect:

UpdateContext({varStatusValue:""});

 On Assigned to me OnSelect:

UpdateContext({varMyValue:true});

On All Users on Select:

UpdateContext({varMyValue:false});

That will work as below:

Choice Values.gif

 

Please let me know if you see any issue, I am always happy to help.

 

Regards,

Krishna

If you see this reply helped Mark it as the solution and give a thumbs-up. 

 



I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a THUMS-UP and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.

Drrickryp
Super User
Super User

Hi @ppl 

The filtering of a gallery is usually done in the Items property of the gallery itself as shown in the screenshot, not by the controls outside of the gallery themselves.  Additional filters can be added by using And(&&) and Or( || ) to reference additional controls such as the TextSearchBox in Filter([@'Facility Desk'], StartsWith(Title, TextSearchBox1.Text)).  For your example, you could add a Radio control with items property ["Plant 1","Plant 2" ].  That is the principle behind how galleries are usually filtered.  @KrishnaV has provided you with a detailed way to solve your particular problem using the Items property of the gallery.
Annotation 2020-05-16 134555.png

Can you write me an example of code when you use And(&&) and Or( || ) to reference additional controls. Because if I am trying to use both functions (Which @Anonymous advice to me and my function SortByColumns(Filter([@'Facility Desk'], StartsWith(Title, TextSearchBox1.Text)), "Created", If(SortDescending1, Descending, Ascending)) I get an error:

111111111.png

 

 

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,000)