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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
karkar
Helper III
Helper III

IN OPERATOR in PowerBi

 

 

I want to perform the following in Power Bi..

 

If Diagnosis_code  in('125','126', '127', '128') then category=Proc1

else if Diagnosis_code in('225','226', '227', '228') then category=Proc2

else category=Null

 

Thanks

1 ACCEPTED SOLUTION

Hi @karkar,



Thanks for the reply. I need help with the syntax while creating a column in the query editor.


Based on my test, the formula(M) below should work in your scenario. Smiley Happy

= if List.Contains({125,126,127,128},[Diagnosis_code]) then "Proc1"
else if List.Contains({225,226,227,228},[Diagnosis_code]) then "Proc2"
else null

 

Regards

View solution in original post

8 REPLIES 8
dkay84_PowerBI
Microsoft Employee
Microsoft Employee

You can either add a column in the query editor or use DAX to create a calculated column.  The syntax will differ depending on the choice.

 

With DAX it essentially will be the same as an excel IF() statement, or you can use the SWITCH(TRUE()) type of argument which may offer performance improvement. 

Thanks for the reply. I need help with the syntax while creating a column in the query editor.

 

Regards

Hi @karkar,



Thanks for the reply. I need help with the syntax while creating a column in the query editor.


Based on my test, the formula(M) below should work in your scenario. Smiley Happy

= if List.Contains({125,126,127,128},[Diagnosis_code]) then "Proc1"
else if List.Contains({225,226,227,228},[Diagnosis_code]) then "Proc2"
else null

 

Regards

@v-ljerr-msft - What if this "list" or Column is Alpha-Neumerical column, can we still use the List.Contains function?

Hello V,

 

Thanks for helping me .I have not yet tried this formulae and did it the manual way.

 New Field is the name of the field we are creating???

NEW FIELD= if List.Contains({125,126,127,128},[Diagnosis_code]) then "Proc1"
else if List.Contains({225,226,227,228},[Diagnosis_code]) then "Proc2"
else null

Also I noticed you used the LIST.CONTAINS......is it  internal to Power BI ?

Is LIST.CONTAINS POWER BI way of telling to read the values being passed? 

 

Thanks

Hi @karkar,


 New Field is the name of the field we are creating???


Yes, it is.


Also I noticed you used the LIST.CONTAINS......is it  internal to Power BI ?

Is LIST.CONTAINS POWER BI way of telling to read the values being passed? 


LIST.CONTAINS is Power Query M formula language which is optimized for building highly flexible data mashup queries. It's a functional, case sensitive language similar to F#, which can be used with Power BI Desktop, Power Query in Excel, and Get & Transform in Excel 2016. Smiley Happy

 

Regards

The syntax for if statements in the query editor is:

 

if *CONDITION* then *RESULT* else *ALTERNATE RESULT*

 

the "if-then-else" should be lower case

 

Also consider wrapping in "try-otherwise" to catch errors

 

You can learn more about these functions via a basic web search for Power Query language (M language)

I should mention that you will need to use multiple statements, for example:

 

if *CONDITION* then *RESULT* else if *CONDITION 2* then *RESULT 2* else if... else *ALTERNATE RESULT*

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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