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?
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)”
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)”
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.
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)))
Check out new user group experience and if you are a leader please create your group
Did you miss the call?? Check out the Power Apps Community Call here!
See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.
ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.