Forum Discussion
IN OPERATOR in PowerBi
- 9 years ago
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. :smileyhappy:
= if List.Contains({125,126,127,128},[Diagnosis_code]) then "Proc1" else if List.Contains({225,226,227,228},[Diagnosis_code]) then "Proc2" else nullRegards
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.
- karkar9 years agoHelper III
Thanks for the reply. I need help with the syntax while creating a column in the query editor.
Regards
- v-ljerr-msft9 years agoMicrosoft Employee
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. :smileyhappy:
= if List.Contains({125,126,127,128},[Diagnosis_code]) then "Proc1" else if List.Contains({225,226,227,228},[Diagnosis_code]) then "Proc2" else nullRegards
- nirvana_moksh7 years agoImpactful Individual
v-ljerr-msft - What if this "list" or Column is Alpha-Neumerical column, can we still use the List.Contains function?
- dkay84_PowerBI9 years agoMicrosoft Employee
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)
- dkay84_PowerBI9 years agoMicrosoft Employee
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*