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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
alice11987
Helper I
Helper I

Convert code to Power Query

Hi, I would like to replicate the similar conditional column in Power Query, How should I do it?

 

 

IF(
Attribute("Spend Category") !=null 
   && Attribute("Spend Category").Substring(0,2).In(
[
"ZZ"
]
),
"No",
"Yes"
)

 

 

Thank you

 

1 ACCEPTED SOLUTION
johnyip
Solution Sage
Solution Sage

@alice11987 Try the following:

 

 

 #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Custom", each if Text.StartsWith([Spend Category], "ZZ") and Spend Category] <> null  then "No" else "Yes")

 

where "#Changed Type" should be changed to the appropraite names that your data preparation step is using.

 



Please mark my post as the solution if this answers your question!
Appreciate your Kudos !!

View solution in original post

2 REPLIES 2
AllisonKennedy
Community Champion
Community Champion

@alice11987  What are you wanting to acheive in English? I'm not familiar with the code you've posted, but if I understand it correctly I agree with @johnyip 

 

In Power Query, click Add Column > Custom Column , and then paste this code:

 

if Text.Contains(Text.Start([Spend Category], 2), "ZZ") and [Spend Category] <> null then "No" else "Yes"

 

If you have a list of other things that you need to include (not just "ZZ"), then try: 

 

if List.Contains( {"ZZ", "DD"}, Text.Start([Spend Category], 2)) and [Spend Category] <> null then "No" else "Yes"


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

johnyip
Solution Sage
Solution Sage

@alice11987 Try the following:

 

 

 #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Custom", each if Text.StartsWith([Spend Category], "ZZ") and Spend Category] <> null  then "No" else "Yes")

 

where "#Changed Type" should be changed to the appropraite names that your data preparation step is using.

 



Please mark my post as the solution if this answers your question!
Appreciate your Kudos !!

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors