Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ckurir
Frequent Visitor

How to use wild cards like * and ? ind power query filter list

How can I use a wild card in a filter for a list?

 

Eg, I have values like

 

AB12

AB234

AB7012

AB7790

 

And I want to filter all AB7???, that is all starting with AB and a 7000 thounds number

 

1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

Table.SelectRows(#"Previous Step", each [Column Name] >= "AB7000" and [Column Name] <= "AB7999"),

View solution in original post

15 REPLIES 15
Rickmaurinus
Helper V
Helper V

Power Query does not natively support wildcards. There are some alternative routes you could take, though. For instance: 

  • Text.StartsWith( "MyText", "My" ) resembles SQL's WHERE x = 'My%'
  • Text.EndsWith( "MyText", "xt" ) resembles SQL's WHERE x = '%xt'

Once you get to more trickier ones like wildcard characters you will need to write custom functions. Wildcards are often represented by ? or _. 

 

I wrote an article on the different approaches that work for these type of wildcards and others. 

 

https://gorilla.bi/power-query/wildcards/

 

It can get a little complex. I hope for regex support or wildcards in the future, though. 

 

--------------------------------------------------

@ me in replies or I'll lose your thread

 

Master Power Query M? -> https://powerquery.how

Read in-depth articles? -> BI Gorilla

Youtube Channel: BI Gorilla

 

If this post helps, then please consider accepting it as the solution to help other members find it more quickly.

 

Anonymous
Not applicable

You could extract the Text.AfterDelimiter "AB7" and test its length (Text.Length) - if it's three then okay.

 

It works if there's no numbers involved too 🙂

 

v-eqin-msft
Community Support
Community Support

Hi @ckurir ,

 

Agree with @ronrsnfld , the wildcard filter is not directly available in power query. You could follow  @AnkitKukreja ‘s suggestion by using Text.StartsWith() to locate the string.

 
If you also want this in power bi, let the power bi community to know this things and give your votes at power bi site's feedback - Ideas
 
Here are similar ideas:
 
 

Best Regards,
Eyelyn Qin

AnkitKukreja
Super User
Super User

You can try M code like Text.StartsWith.

#"Filtered Rows" = Table.SelectRows(#"Changed Type", each Text.StartsWith([Column1], "AB7"))

Posting the full code I tried for your question.

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnQyNFKK1QExjIxNoCxzA7igubmlgVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each Text.StartsWith([Column1], "AB7"))
in
#"Filtered Rows"

If my response has successfully addressed your question or concern, I kindly request that you mark this post as resolved. Additionally, if you found my assistance helpful, a thumbs-up would be greatly appreciated.
Thanks,
Ankit Kukreja
www.linkedin.com/in/ankit-kukreja1904

This wil also select eg AB71, but it was supposed to select any thing starting with AB and a 7'thousand number

 

Hi @ckurir 

I could have think of a solution what was present in the question.
Is it possible for you to share some more datapoints and your expected answer? I might give it a shot.

But as @v-eqin-msft suggested the wildcard filter are not available directly in power query, maybe we can use it with dax if you can share your pbix or data in excel for me to try.

 

If my response has successfully addressed your question or concern, I kindly request that you mark this post as resolved. Additionally, if you found my assistance helpful, a thumbs-up would be greatly appreciated.
Thanks,
Ankit Kukreja
www.linkedin.com/in/ankit-kukreja1904

Like the example above, it could be:

AB12

AB234

AB27123

AB712345

AB7012

AB7790

 

Here only the last two (AB7012 and AB7790) should be selected

Hi @ckurir 

 

If you've few only few conditions like in this example then this might help.

 

AnkitKukreja_0-1642170744137.png

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnQyNFKK1QExjIxNYCxzQyNjKBvENDGFcQzgqs3NLQ2UYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Test = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Test", type text}}),
#"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Custom", each if [Test] = "AB712345" then "NA" else if Text.StartsWith([Test], "AB7") then [Test] else "NA")
in
#"Added Conditional Column"

 

Please mark it as a solution if it answers your question.

 

If my response has successfully addressed your question or concern, I kindly request that you mark this post as resolved. Additionally, if you found my assistance helpful, a thumbs-up would be greatly appreciated.
Thanks,
Ankit Kukreja
www.linkedin.com/in/ankit-kukreja1904

Not really good. I have hunrdreds of lines. There could also be AB723 or similar which is not to be selected. Maybe something with lenght as a condition could be used?

Hi! @ckurir 

 

That was my suggestion earlier. If you can provide the data and the expected result, then I might be able to help you.

 

If my response has successfully addressed your question or concern, I kindly request that you mark this post as resolved. Additionally, if you found my assistance helpful, a thumbs-up would be greatly appreciated.
Thanks,
Ankit Kukreja
www.linkedin.com/in/ankit-kukreja1904

I cannot send you the real data due to GDPR. But the examples I gave is a good example. But I am not so keen any more to get the actual problem solved, I already accepted a solution. But I was just wondering if it is not possible to use wildcards as many other programming languages provides. But is seems not to be the case.

 

 

ronrsnfld
Super User
Super User

Table.SelectRows(#"Previous Step", each [Column Name] >= "AB7000" and [Column Name] <= "AB7999"),

Nice workround.

But is wildcards not possible? So it will be more difficoult to eg filter like XY??*9 ?

Try using TEXT.STARTSWITH() or TEXT.CONTAINS()

I do not believe wild cards are part of the M language specification.

 

You could implement Regular expressions (either in Javascript, Python or R), but that seems like more trouble than using straight text filters; and might be less efficient on large databases. 

 

However, I believe you can use wild cards in the Power BI filters, but you asked specifically about Power Query.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors