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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
BeLocke
New Member

Text.Contain in M Query to check if Value Column Contains Consonant

Hello,

I need help. I am using a table to create a new column that checks a column named Value for a consonant. If it contains a consonant, the column is true. Otherwise, it is false.

The formula works in the screenshot below, but it still shows an error on some that should be true.

BeLocke_0-1731688617153.png

When I clicked on the error, I got the following: It is registered as false, but  PowerBI can not convert the type over.

BeLocke_1-1731688825904.png

 

Below is my code for the column( I shortened it to letters b and z, but it follows the same pattern b-z, no vowels included):

 

= Table.AddColumn(#"Filtered Rows", "Consonant Passed", each if Text.Contains([Value], "b", Comparer.OrdinalIgnoreCase)= true then true else if Text.Contains([Value] = "z", Comparer.OrdinalIgnoreCase)= true then true else false)

 

BeLocke_2-1731689391228.png

 

1 ACCEPTED SOLUTION

Use this

List.ContainsAny(Text.ToList(Text.Lower([Value])), List.Difference({"b".."z"}, {"e", "i", "o", "u"}))

View solution in original post

5 REPLIES 5
ThxAlot
Super User
Super User

Easy enough if you can incorportate python script,

ThxAlot_0-1731704641431.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCslILUpVyCxWyMsvycjMS1eK1YlWSkpOUUhLz1DIys4B8/MVMksVEhUUUpViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Value = _t]),
    #"Run Python script" = Python.Execute("dataset['consonant'] = dataset['Value'].str.contains(r'[^aeiou ]',case=False,regex=True)",[dataset=Source]),
    dataset = #"Run Python script"{[Name="dataset"]}[Value],
    #"Changed Type" = Table.TransformColumnTypes(dataset,{{"consonant", type logical}})
in
    #"Changed Type"

ThxAlot_1-1731704709199.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



watkinnc
Super User
Super User

Just remove both of the "= true", because that's already implied by the via function return value--in other words, if text contains this then do this else do that.

 

--Nate 


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
Vijay_A_Verma
Super User
Super User

You can use this in a custom column

List.ContainsAny(Text.ToList([Value]), List.Difference({"b".."z"}, {"e", "i", "o", "u"}, Comparer.OrdinalIgnoreCase))

 

That removes errors, which is excellent, but still created some false positives. 

All the false positives are capital letters; they need to be case-insensitive.

BeLocke_0-1731692763770.png

 

Use this

List.ContainsAny(Text.ToList(Text.Lower([Value])), List.Difference({"b".."z"}, {"e", "i", "o", "u"}))

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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

October NL Carousel

Fabric Community Update - October 2024

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