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
And when I press Not assigned button it will show items only with Status = New
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.
I wrote functions like this, but they are not working.
Solved! Go to Solution.
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:
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.
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:
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.
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.
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: