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
Pandadev
Post Prodigy
Post Prodigy

Replicate Dax SWITCH code in Query editor

Hi is there a way to add a custom column in query editor and replicate this dax code

Res = SWITCH(TRUE(),
AND([Event Code]="Q3", [MarketSector]="Commercial"), "AW",
AND([Researcher]<>"SLR", [OperatorTypeCode]="16"), "SLR",
AND([Researcher]="SLR", [OperatorTypeCode]="16"), "SLR",
AND([Event Code]="21", [MarketSector]="Commercial" && [Manufacturer]<>"Bing"), "NF",
AND([Event Code]="61", [MarketSector]="Commercial" && [Manufacturer]<>"Bing"), "NF",
AND([Event Code]="71", [MarketSector]="Commercial" && [Manufacturer]<>"Bing"), "NF",
AND([Event Code]="81", [MarketSector]="Commercial" && [Manufacturer]<>"Bing"), "NF",
AND([Event Code]="21", [MarketSector]="Commercial" && [Manufacturer]="Bing"), "MB",
AND([Event Code]="61", [MarketSector]="Commercial" && [Manufacturer]="Bing"), "MB",
AND([Event Code]="71", [MarketSector]="Commercial" && [Manufacturer]="Bing"), "MB",
AND([Event Code]="81", [MarketSector]="Commercial" && [Manufacturer]="Bing"), "MB",
 
AND([Researcher]="", [Researcher]<>"JMY"), "ZZ",
 
[Researcher]
)
1 ACCEPTED SOLUTION

Hi @Pandadev ,

 

Your closing brackets are wrong.

 

IF ([Event Code]="Q3" AND [MarketSector]="Commercial") THEN "AW"
ELSE IF ([Researcher]<>"SLR" AND [OperatorTypeCode]="16") THEN "SLR" 

 

There is a nice example on the following blog:
https://www.fourmoo.com/2018/11/27/multiple-conditions-for-a-conditional-column-in-power-query/

Pragati11_0-1617810488532.png

 

Thanks,

Pragati

 

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

View solution in original post

6 REPLIES 6
Pragati11
Super User
Super User

Hi @Pandadev ,

 

You can add a custom column on Query Editor in Power BI using IF-ELSE multiple conditional statements. Read more about it here: https://docs.microsoft.com/en-us/powerquery-m/m-spec-conditionals

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Thanks I looked at that solution , but I need it to check two different criteria , which was not available in the conditional column

in this example  below it is looking at Event Code =Q3 and MarketSector = Commercial , then change to AW

AND([Event Code]="Q3", [MarketSector]="Commercial"), "AW",

Hi @Pandadev ,

 

It will be a simple IF AND ELSE condition. Something like below: (you can find many examples online)

 

 IF([Event Code]="Q3" AND [MarketSector]="Commercial") THEN "AW" ELSE IF ......

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

I tried this but it shows an error on first AND , token comma expected

IF(
[Event Code]="Q3" AND [MarketSector]="Commercial") THEN "AW"
ELSE IF
[Researcher]<>"SLR" AND [OperatorTypeCode]="16") THEN "SLR" ))

Hi @Pandadev ,

 

Your closing brackets are wrong.

 

IF ([Event Code]="Q3" AND [MarketSector]="Commercial") THEN "AW"
ELSE IF ([Researcher]<>"SLR" AND [OperatorTypeCode]="16") THEN "SLR" 

 

There is a nice example on the following blog:
https://www.fourmoo.com/2018/11/27/multiple-conditions-for-a-conditional-column-in-power-query/

Pragati11_0-1617810488532.png

 

Thanks,

Pragati

 

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Thanks for the example , I have now managed to get it to work 

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