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
PooBIDeveloper
Frequent Visitor

Default value in M Query

Hi All,

 

I have a column where a value is fixed,i am using custom column for this,but its showing error.

Below is the Query where i am trying to make a validation in the column if it has the value Z then its valid else invalid.

 

if
List.Contains({"Z"})
then "Valid"
else "Invalid"

Thanks

1 ACCEPTED SOLUTION
watkinnc
Super User
Super User

This should be done with Text.Contains instead of List.Contains:

 

= Table.AddColumn(PriorTableOrStepName, "Validator", each if Text.Contains([Column1], "Z") then "Valid" else "Invalid", type text)

 

--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!!

View solution in original post

2 REPLIES 2
watkinnc
Super User
Super User

This should be done with Text.Contains instead of List.Contains:

 

= Table.AddColumn(PriorTableOrStepName, "Validator", each if Text.Contains([Column1], "Z") then "Valid" else "Invalid", type text)

 

--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!!
Vera_33
Resident Rockstar
Resident Rockstar

Hi @PooBIDeveloper 

 

So you are trying to see this paticular column has at least 1 Z?

Vera_33_0-1645249438975.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WilKK1YlWcgSTQHYsAA==", 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}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Contains(#"Changed Type"[Column1],"Z"))
in
    #"Added Custom"

 

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