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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
asmagh
Helper I
Helper I

Multiple condition in if

hello , please i need some help here what i have 
if ( ca = 0 ) in date1 and ca <>0 in date2 then 'new' 

else if ( ca in date1 < ca in date2 ) then 'up')

else if (ca in date 1 > ca in date then 'down')

else if ca <> 0  in date1 and ca = 0 in date 2 then 'unkhnown')

 

so i try to write it with dax like this    

if ( (ca=0 , date1 ), 'nouveaux' , if(ca <>0 , date2), 'nouveaux', if ((ca , date1 )<(ca , date2), 'croissance', if ((ca , date1 )>(ca , date2), 'perte',if((ca<>0 , date1 ), (ca =0 , date2),'null'))))) 

or 

if ( (ca=0 , date1 ) && (ca <>0 , date2); 'nouveaux';  if ((ca , date1 )<(ca , date2); 'croissance'; if ((ca , date1 )>(ca , date2) ; 'perte' ; if((ca<>0 , date1 )&&(ca =0 , date2);'null')))))


I have a problem to acces to power BI so until i found a solution i want to be sure that my dax querry is right .
Any suggestion please 
thank you 

1 ACCEPTED SOLUTION
Floriankx
Solution Sage
Solution Sage

Hello, Switch should be perfect.

 

I assume two measures,

CA1 for ca in date1 and CA2 for ca in date2.

 

Switch(
TRUE(),
[CA1]=0 && [CA2]<>0, 'new', --condition 1
[CA1]>[CA2], 'up', --condition 2
[CA1]<[CA2], 'down' --condition 3
[CA1]<>0 && [CA2]=0, 'unknown' --condition 4
BLANK()) --else

For further information check this article.

 

I hope this helps. I want miss the SWITCH function anymore.

View solution in original post

14 REPLIES 14
Floriankx
Solution Sage
Solution Sage

Hello, Switch should be perfect.

 

I assume two measures,

CA1 for ca in date1 and CA2 for ca in date2.

 

Switch(
TRUE(),
[CA1]=0 && [CA2]<>0, 'new', --condition 1
[CA1]>[CA2], 'up', --condition 2
[CA1]<[CA2], 'down' --condition 3
[CA1]<>0 && [CA2]=0, 'unknown' --condition 4
BLANK()) --else

For further information check this article.

 

I hope this helps. I want miss the SWITCH function anymore.

thank you it work but i have juste a little problem i want to regroup my data by  criterion . so i want to have those criterion in line and CA1 and CA2 in column ; the problem that power consider it as a measure so it automatically put it in colunm what ken i do please seg.PNG

Do you have several rows per Code Client?

i didn't understand what do you mean by several rows but here what i want to do in first place res.PNG

 

after that i want to drill down in detail and display the client that belong to each class of new / up / down / vide

Hello,

 

I understand your desired output perfectly.

How does your row data look like?

 

Best regards

mntper1 and mntper2 are amount so they are number but seg client is a switch function that i create in a measure by your help 
seg_client = Switch( TRUE(); [MntPer1] = 0 && [MntPer2]<>0; "new"; --condition 1
[MntPer1]<[MntPer2]; "up"; --condition 2
[MntPer1]>[MntPer2]; "down" ; --condition 3
[MntPer1]<>0 && [MntPer2]=0; "unknown" ; --condition 4
BLANK()) --else

and it's a text according to power bi 

Did you erse the '--condition x' ? They were just for information and not meant to be part of the formula.

 

Calculated column should be:

= Switch( TRUE(); [MntPer1] = 0 && [MntPer2]<>0; "new";
[MntPer1]<[MntPer2]; "up";
[MntPer1]>[MntPer2]; "down" ;
[MntPer1]<>0 && [MntPer2]=0; "unknown" ;
BLANK())

yes i khnow it's just a comment "-- condition" it doesn't affect the formula 

Hello,

 

try to create a calculated column with this formula.

he doesn't accept the switch in it 😕 

Hello, try to use the columns names instead of CA1 and CA2.

 

Best regards.

CA1 and CA2 are measure that i created in power bi to use them 

Greg_Deckler
Super User
Super User

Can you post an example of your data? I don't understand ca=0 in date1? 

 

Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

i have problem to access to my data but 'CA' it's a measure ; an amount and date1 is a date from Dimension date that's why i called date1 because i have with 2 date that's why 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.