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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
jasmine9
Helper I
Helper I

If then else condition multiple statements after then

Hi,

 

1. Based on my If condition, can I change the value of a different column?

For eg: if (pet = cat) then var1 = animal 

 

2. In my If condition, I want to be able to write multiple statements both under "then" and "else".

Is this possible in PowerQuery or PowerBI and if not, what is the alternative?

For eg:  if (pet=cat) then {var1=animal ; var2= mammal; }  else { var1= noncat; var2="nonmammal"} 

 

Thanks,

Jas

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi @jasmine9 ,

 

Use "switch" function for each var,see below link:

https://docs.microsoft.com/en-us/dax/switch-function-dax

You may take below example for instance:

Measure for var1=Switch(
True(),
MAX([Pet])="cat","animal",
"noncat")
 



Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

 

View solution in original post

2 REPLIES 2
v-kelly-msft
Community Support
Community Support

Hi @jasmine9 ,

 

Use "switch" function for each var,see below link:

https://docs.microsoft.com/en-us/dax/switch-function-dax

You may take below example for instance:

Measure for var1=Switch(
True(),
MAX([Pet])="cat","animal",
"noncat")
 



Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

 

Ashish_Mathur
Super User
Super User

Hi,

You cannot do it al in one formula.  You will have ot use 2 formulas - one each for var1 and var2.

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.