Filter Gallery with Combo box in Power Apps
For this exercise, we use the following excel file filter-combo-data.xlsx.
This example shows how to Filter list of State and District based on selected Combo box control values.
Step 1: Open a blank canvas app or open the existing app and add a new screen by selecting the New Screen option.
Step 2: On the + Insert tab, select Gallery and then select Blank Vertical gallery.
Step 3: Connect the gallery to the Data source by setting the Items property to Table1.
Step 4: Add three Text label controls, and bind it to their respective columns.
Step 5: On the + Insert tab, select Input and then select Combo box. Repeat the step again to add one more combo box control.
Step 6: On the first Combo box control, set the Items property to the following formula.
Power Apps Formula
To get information about the Distinct function, click here.
On the second Combo box control, set the Items property to the following formula.
Power Apps Formula
Step 7: Now select Gallery control and set the Items property to the following formula:
Power Apps Formula
Filter( Table1, State = (ComboBox1.Selected.Value) || IsBlank(ComboBox1.Selected.Value), Type = (ComboBox2.Selected.Value) || IsBlank(ComboBox2.Selected.Value) )
Here, Value is the name of the column. Explanation: This is a PowerApps formula used to filter a table named "Table1" based on two conditions: "State" and "Type". The filter formula uses two ComboBox controls named "ComboBox1" and "ComboBox2" to dynamically set the filter criteria. The first condition in the formula checks whether the "State" column in the "Table1" matches the selected value in "ComboBox1". The "||" symbol means "OR", so if the selected value in "ComboBox1" is blank (i.e., no value is selected), the condition will still return true.
The second condition in the formula checks whether the "Type" column in the "Table1" matches the selected value in "ComboBox2". Again, the "||" symbol means "OR", so if the selected value in "ComboBox2" is blank, the condition will still return true.
Overall, the formula returns a filtered table where the "State" and "Type" columns match the selected values in the corresponding ComboBox controls. If no value is selected in a ComboBox, the filter will still be applied, but the corresponding column will match all values (i.e., the filter will be ignored for that column).
When we select for State Haryana, the list is filtered according to the state. Here we are not selecting any Type, so all type values are available in the gallery.
Here, we select the Type also. So, the gallery is filtered according to the State and Type combo box value.
We can do one thing that if no choice in the combo box is selected than it shows all options are selected. For this we change the NoSelectionText property of the combo box.
Select both the combo box controls, and update the NoSelectionText property to the “All” value. So, when no option is selected from the Combo box it gives a visual view that shows all the options are selected.
Let’s preview the app. When we select the state, the NoSelectionText is not shown and it is shown in the other control, where no option is selected.
Note: In the above scenario the filter is based on the current selected value from the combo box.
If we want to filter the data according to the multiple selected items of the combo box control we can use the following Power Apps formula.
Power Apps Formula
Filter( Table1, State in (ComboBox1_1.SelectedItems) || IsBlank(ComboBox1_1.Selected.Value), Type in (ComboBox2_1.SelectedItems) || IsBlank(ComboBox2_1.Selected.Value) )
Explanation: We are using PowerApps to filter a table called "Table1" using two combo boxes named "ComboBox1_1" and "ComboBox2_1".
The formula you provided is using the Filter function to filter Table1 based on two conditions. The first condition is checking if the State column in Table1 matches any of the selected items in ComboBox1_1 or if the ComboBox1_1 is blank. The second condition is checking if the Type column in Table1 matches any of the selected items in ComboBox2_1 or if the ComboBox2_1 is blank.
In other words, this formula will filter Table1 based on the selected values in ComboBox1_1 and ComboBox2_1, but it will also return all rows in Table1 if either ComboBox1_1 or ComboBox2_1 is blank.
It's important to note that the "IsBlank" function is checking if the Selected.Value property of the ComboBox is blank, not the SelectedItems property. The SelectedItems property returns a collection of all the selected items in the ComboBox, while the Selected.Value property returns the value of the currently selected item in the ComboBox. If we select only one state and two types, the records are filtered in the gallery as shown in the figure.