cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MSC01
Frequent Visitor

Filtering gallery by combobox AND selected

Hi, i am trying to filter a gallery by 2 options. 

1st option i have managed to achieve by using a combo box and applying the following to the gallery - Filter('table', name in ComboBox.SelectedItems.Name) and this displays all the users with the selected options from the combobox.

 

the 2nd option is where i am stuck, i want to be able to have the option where i can filter the gallery to show users that only have for example all 3 items selected from the combobox. 

e.g. if A,B is selected from a list of A, B, C, D this will give a list of users with only A AND B not A or B.

John is displayed in the list as he has items A and B

Mick has items A and C so will not show in the list

Ben has only items B but will not show in the gallery list as he does not have A AND B.

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-xiaochen-msft
Community Support
Community Support

Hi @MSC01 ,

 

I did a test for you.

 

1\ Add a button control and set its onselect property to:

ClearCollect(Col,{code:"9901",resource:"andrew",postcode:"ol14bb"},{code:"baa",resource:"andrew",postcode:"ol14bb"},{code:"baa",resource:"ian",postcode:"le135hg"},{code:"baa",resource:"john",postcode:"ol86bh"},{code:"baa",resource:"antony",postcode:"ox61ny"},{code:"9901",resource:"ann",postcode:"b123an"})

 

2\ Add a combo box control and set its Items property to:

Distinct(Col,code)

 

3\ Add a gallery control and set its Items property to:

Filter(Ungroup(ForAll(Distinct(Col,resource) As A,If(CountRows(Filter(Ungroup(ForAll(ComboBox2.SelectedItems As B,Filter(Col,resource=A.Result,code=B.Result)),"Value"),IsBlank(code)))>0,Blank(),Ungroup(ForAll(ComboBox2.SelectedItems As B,Filter(Col,resource=A.Result,code=B.Result)),"Value"))),"Value"),!IsBlank(code))

 

4\ The result is as follows:

v-xiaochen-msft_0-1617934303409.png

v-xiaochen-msft_1-1617934314097.png

v-xiaochen-msft_2-1617934344010.png

Best Regards,
Wearsky
If my post helps, then please consider Accept it as the solution to help others. Thanks.

 

 

View solution in original post

7 REPLIES 7
v-xiaochen-msft
Community Support
Community Support

Hi @MSC01 ,

 

Could you tell me:

What is your data source? Is it a sharepoint list?

Do you have a Choice column? Are there four options "A", "B", "C", and "D"?Does it allow multiple selections?

 

If my assumptions are correct, I did a test for you.

1\ This is my list 'LIST105'. 'TestChoiceColumn' is a choice column. It allows multiple selections.

v-xiaochen-msft_0-1617763742120.png

2\ Add a combo box control 'ComboBox1' and set its Items property to:

Choices(LIST105.TestChoiceColumn)

 

3\ Add a gallery control and set its Items property to:

Filter(ForAll(LIST105 As A,If(CountRows(Filter(ForAll(ComboBox1.SelectedItems As B,If(B.Value in A.TestChoiceColumn.Value,B.Value)),!IsBlank(Value)))=CountRows(ComboBox1.SelectedItems),A)),!IsBlank(Title))

 

4\ The result is as follows:

v-xiaochen-msft_1-1617764432476.png

v-xiaochen-msft_2-1617764448908.png

 

Best Regards,
Wearsky
If my post helps, then please consider Accept it as the solution to help others. Thanks.

 

MSC01
Frequent Visitor

Hi, Thank you for your response.

 

My data source is CDS. The combobox is not a choice column. the gallery is also cds. the combobox allows for multiple choices to be selected as it is a long list of "criteria" for users . The gallery then filters the list based on the selected items in the combobox and views this. within the gallery is the name of the criteria selected and also the user belonging to that criteria. There can be multiple users belonging to the criteria selected in the dropdown.

 

v-xiaochen-msft
Community Support
Community Support

Hi @MSC01 ,

 

So, what's the "criteria" ? 

What's the formula of combobox Items property?

I don't know where the ABCD mentioned in your article comes from.

 

Best Regards,
Wearsky

MSC01
Frequent Visitor

Hi,

 

The dropdown/combobox is a list of codes connected to CDS.

 

The gallery is connected to CDS and contains users that have those codes. 

The gallery is filtered via the drop down, e.g. Filter('codes', name in codesComboBox.SelectedItems.Name)

Both connected to CDS same table where it has users, codes and postcodes.

The gallery contain the user name, the code belonging to the user, and their postcode. 

I want to be able to filter the gallery so that it shows for example, from the combobox if i select the codes 9901 and baa, it will only show andrew as he has both codes

MSC01_1-1617888514472.png

 

 

v-xiaochen-msft
Community Support
Community Support

Hi @MSC01 ,

 

I did a test for you.

 

1\ Add a button control and set its onselect property to:

ClearCollect(Col,{code:"9901",resource:"andrew",postcode:"ol14bb"},{code:"baa",resource:"andrew",postcode:"ol14bb"},{code:"baa",resource:"ian",postcode:"le135hg"},{code:"baa",resource:"john",postcode:"ol86bh"},{code:"baa",resource:"antony",postcode:"ox61ny"},{code:"9901",resource:"ann",postcode:"b123an"})

 

2\ Add a combo box control and set its Items property to:

Distinct(Col,code)

 

3\ Add a gallery control and set its Items property to:

Filter(Ungroup(ForAll(Distinct(Col,resource) As A,If(CountRows(Filter(Ungroup(ForAll(ComboBox2.SelectedItems As B,Filter(Col,resource=A.Result,code=B.Result)),"Value"),IsBlank(code)))>0,Blank(),Ungroup(ForAll(ComboBox2.SelectedItems As B,Filter(Col,resource=A.Result,code=B.Result)),"Value"))),"Value"),!IsBlank(code))

 

4\ The result is as follows:

v-xiaochen-msft_0-1617934303409.png

v-xiaochen-msft_1-1617934314097.png

v-xiaochen-msft_2-1617934344010.png

Best Regards,
Wearsky
If my post helps, then please consider Accept it as the solution to help others. Thanks.

 

 

View solution in original post

MSC01
Frequent Visitor

Thanks for this, i have managed to progress with this, only difference i did was use the original data within the gallery- ClearCollect(Col, ForAll(Gallery1.AllItems,{code.Text, user: userNameLabel.Text})) as it was collecting the data as nested or grouped tables.

MSC01
Frequent Visitor

hi is it possible to make the gallery switch between 2 sets of views - the original and then using the formula mentioned above. if a checkbox is unselected then its the original view of the list and if selected its the filtered list using the formula in the image

MSC01_0-1618494913586.png

 

 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (75,578)