cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DuncanH
New Member

Set field for filter operation by combo box

I would like to filter a DataTable (or any data source) and select the colum name 'fieldname' for filtering dynamically for comparison with 'someValue'

 

Filter(MyTable, fieldName > someValue)

 

To make the filter dynamic, there are many examples how to set someValue by an input devive but I would like to change the chosen column in the table, that is used for the comparison, not the value it is compared with.

 

My problem is that the Combo Box returns a string variable with ComboBox,SelectedText.Value

I understand that the Filter function requires a different data type.

How can I choose the Combo Box to or the Filter to match the data types?

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @DuncanH ,

I understand your requirement now.

Currently, this purpose cannot be achieved. We cannot dynamically define columns in the filter criteria. Since the column name/Table name can only be hardcoded in PowerApps. This is a by default feature that we cannot do some customizations.

On the other hands, yes, you have mentioned the workaround. Although this workaround may be a little tricky when you have a large number of columns, but at least this solution did achieve your purpose(At the moment I don't know any other solutions than this can meet your requirement).

Filter(Table1, If( Dropdown1.SelectedText.Value = "Housenumber", Housenumber>10, If( Dropdown1.SelectedText.Value = "IdNumber", IdNumber>10, PhoneNumber>10)))

Best regards,

Allen

View solution in original post

3 REPLIES 3
v-albai-msft
Community Support
Community Support

Hi @DuncanH ,

Which data type do you want to returned from the combo box? Do you want to use the result of combo box instead of using “someValue” in your formula?

If you want to get a text result(the combo box has single choice), you can use “ComboBox.Selected.Value”. Then you can use formula like

“Filter(MyTable, fieldName = ComboBox.Selected.Value)”

v-albai-msft_0-1617874134890.png

 

If the combo box is multiple-choices, you can use “ComboBox.SelectedItems.Value” to get a table, then you can use formula like “Filter(MyTable, fieldName in ComboBox.SelectedItems.Value)”

v-albai-msft_1-1617874134892.png

Besides, I need to confirm if you are using a combo box or a dropdown, since SelectedText is the property of dropdown control.

If I misunderstand, please provide more information(better with screenshots) for helping me better understand your requirement.

Best regards,

Allen

DuncanH
New Member

Hi Allen,

Thank you for taking the time to respond.

 

Indeed I am using a Dropdown menu.

De items in the Dropdown menu are the names of the columns in my table:

 Items:["HouseNumber", "IdNumber", "PhoneNumber"]

 

Then I would like to be able to filter on either "HouseNumber", "IdNumber" or "PhoneNumber" So my filter on the Table1 reads:

 

Filter(Table1, Dropdown1.Selected.Value > 10)

 

And depending on the selected value the appropriate filtering should be applied.

 

But this does not work because the Dropdown1.Selected.Value  is a string and not a column name.

 

I did some more searching and found that one solution would be to use If or Switch statements.

 

Filter(Table1, If( Dropdown1.SelectedText.Value = "Housenumber", Housenumber, If( Dropdown1.SelectedText.Value = "IdNumber", IdNumber, PhoneNumber)))

 

But that becomes a problem when there are a large number of columns.

 

I was hoping for a more elegant solution where I can select the appropriate column name object based on its name.

 

 

Hi @DuncanH ,

I understand your requirement now.

Currently, this purpose cannot be achieved. We cannot dynamically define columns in the filter criteria. Since the column name/Table name can only be hardcoded in PowerApps. This is a by default feature that we cannot do some customizations.

On the other hands, yes, you have mentioned the workaround. Although this workaround may be a little tricky when you have a large number of columns, but at least this solution did achieve your purpose(At the moment I don't know any other solutions than this can meet your requirement).

Filter(Table1, If( Dropdown1.SelectedText.Value = "Housenumber", Housenumber>10, If( Dropdown1.SelectedText.Value = "IdNumber", IdNumber>10, PhoneNumber>10)))

Best regards,

Allen

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (2,366)