Microsoft PowerApps: wildcard search

Henrik Hjertstedt
3 min readApr 21, 2021

Do you need to create a wildcard search in Microsoft PowerApps. There is no native support for wildcard searches in PowerApps. But below is one possible solution on how to make it work.

The solution:

Clear(newCollection);
ForAll( Split( TextInput.Text, “*” ) As SplitMe,
Collect( newCollection, Filter( [Your Data Source], Trim(SplitMe.Result) in [Your Data Source Column])
) )

Screen shot of a simple wildcard search in Microsoft PowerApps

Add this code to either the “OnChange” property of your text input or the “OnSelect” property of a button. The data source of your gallery should be set to “newCollection”.

So how does it work:

ForAll and Split: the “ForAll” function creates a loop for each result of the Split function. In the example the wildcard character is set to: * It is possible to enter as many wildcards as you want — for example good*bad*ugly is split in three parts.

An example of how the split function works with the wild card character in PowerApps

Notice here the use the “As” function to make the “Result” property easier to read and distinguish. This is especially helpful when different data sources use the same property name.

The second argument of the “ForAll” function is the action for each loop. This part took a lot of time to get right since there are a lot of actions that are not allowed within the loop. At last, I worked out the solution which simply uses the “Collect” function.

Collect function

Each time the “Collect” function is called it adds new records to the collection. This is different to “ClearCollect” which deletes the existing collection and creates a new one. With “Collect” the items filtered from the data source in the first loop are added first, then the items from the second loop are appended to the same collection. Finally, there is a complete set of results.

Don’t forget to “Clear” the collection each time the action is triggered — otherwise you end up adding to the existing results.

Adding the results to the Gallery

Microsoft PowerApps wild card search in action

Finally we can use the filtered search results in a Gallery. Just set the “Items” property of the Gallery to “newCollection”.

What improvements can be made?

The basic solution works really well. However, what happens if someone puts a wildcard character first or last? What happens if there are trailing spaces? How can you remove duplicate results?

There are quite a few improvements that can be made to the base solution. I have published a complete solution on this page.

--

--

Henrik Hjertstedt

Lawyer and Citizen Developer. Founder of LawChatGPT.com. Passionate for digitalising and automating legal work.