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
101Mathew
Resolver II
Resolver II

Check if each row in a column contains A through Z

I all I've used Text.Remove([Pol Ref], {"0".."9"}), to quickly remove all numric values from a text string column with no problems.

 

I wanted to create a similar, type of custom column, this time to check if each row in a column contains A through to Z

 

So I create another custom column, with the following M code

 

if
  Text.Contains([Postcode], {"A".."Z"})
then "Keep"
 
else "Remove"

 

However the it returns Error on each row for my Postcode column, advising

 

"Expression.Error: We cannot convert a value of type List to type Text.
Details:
    Value=List
    Type=Type"

 

I'm rather new to programming, and new to programming in M.  Can anyone advise a solution for such a newbie?

2 ACCEPTED SOLUTIONS

@Zubair_Muhammad

 

Thank you,  we hit a error at the "then" section of the M coding

 

If seems like M does not allow to create conditional formula onto lists?!?

View solution in original post

@101Mathew

 

It works when I use some sample data

Take a look at attached Excel file's query editor

 

werewr.png


Regards
Zubair

Please try my custom visuals

View solution in original post

4 REPLIES 4
Zubair_Muhammad
Community Champion
Community Champion

@101Mathew

 

Try this revision

 

=if
List.ContainsAny(Text.ToList([Column1]),{"a".."z"}&{"A".."Z"})
then
"Keep"
else
"Remove"

Regards
Zubair

Please try my custom visuals

@Zubair_Muhammad

 

Thank you,  we hit a error at the "then" section of the M coding

 

If seems like M does not allow to create conditional formula onto lists?!?

@101Mathew

 

It works when I use some sample data

Take a look at attached Excel file's query editor

 

werewr.png


Regards
Zubair

Please try my custom visuals

@Zubair_Muhammad

 

Thank you, and sorry

 

I made a mistake with the brackets, it's annoying that Power Query does not give better feedback on issues with my programming.

 

It now works very well.

 

Cheers

Mathew

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.