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

code M for conditional column with two conditions (IF; AND)

I need to create a conditional column where I get two conditions. Example:

 

If the "Error code" column does not start with the text "EAC" and "REV", return the value 1, or return the value 0.

 

I developed this M code to perform this custom column creation, but it presents error:

 

#"Conditional Column Added2" = Table.AddColumn(#"Reordered Columns1", "conditionaldtc", each if not Text.StartsWith([Cod. Erro], "EAC" and "REV") then 1 else 0)

 

would anyone know how to help me?

2 REPLIES 2
wdx223_Daniel
Super User
Super User

#"Conditional Column Added2" = Table.AddColumn(#"Reordered Columns1", "conditionaldtc", each if not List.Contains({"EAC","REV"},[Cod. Erro],each Text.StartsWith(y,x)) then 1 else 0)

Hello, i appreciate your help. But what should I put in X's shoes?

 

In the function, Text.StartsWith(y,x) Should I put the column name for the value of y example: ([Cod. error]), but I would like to analyze all the rows of the column, so what parameter do I put to the value of X?

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