Search code examples
comboboxfilteringpowerapps

Combo Box filtering on PowerApps


I have a DataTable on PowerApps, this DataTable has a State Column, delimiting by comma ( , ).

Like:

AL, AK, AZ, AR, CA, CO, CT, DE, FL, GA, HI

CA

CO

I use a ComboBox to select many options of filtering, like [CA, CO].

But the results only show the exactly text.

CA and CO

But I like to include the first row too, because on the row has CA and CO.

I have this filter function.

Filter(dataSource, States in ComboBox1.SelectedItems.state)

How I can use the filter function or another solutions in PowerApps?


Solution

  • You can use an expression like this one:

    Filter(
        dataSource As ds,
        Sum(
            ForAll(
                ComboBox1.SelectedItems,
                If(ThisRecord.state in ds.States, 1, 0)),
            Value)
            > 0)
    

    Looking at the expression from the inside-out, the idea is to look for all the selected states in the combobox, and if it is contained in the 'States' field of your data source, then it will yield 1, otherwise 0.

    Then we sum all of those values; if any selected state was in the States field, then this sum will be greater than zero, and that's the condition that can be used in the Filter expression.