Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago

How to apply a dynamic filter with specific filtering logic for wildcard search

Hello, 

 

I’m working on a Power BI visual where I need to filter data based on user input that follows a pattern with wildcard search. Essentially, I want the search function to allow for a dynamic filter where, if there is no * at the end, it should end with the value that was searched for. For example, if the user searches for 'text1*text2', the result should return all values that start with "text1" and that end with "text2". If user searches for 'text1*text2*', there is a * at the end, so the operator is 'contains'. Same for searches with 'text1*'.

Here’s my current setup:

  • I’m using the 'contains' operator for filtering, as 'endswith' is not available in the advanced filter API.
  • My current logic works for:
    • text*: It returns all values that contain the specified prefix before the wildcard with operator 'contains'. 
    • text: It returns an exact match using the 'is' operator.

However, for searches like text1*text2, I need the filter to behave as if it uses a 'endswith' operator for the part after the *, when there is no * at the end.

 

Any help is appreciated. Thanks in advance!

1 Reply

  • use SEARCH  (or FIND) to figure out if the search term is at the end of the string or not.