Forum Discussion
Nested If condition
Hi All,
How to make nested if condition in Power BI.
I have to create condition as :
If (Amount is <=1000 and Year is MaxYear) ,
If(Amount is between <1000 and Year = MaxYear-1) then "Period1" ,
If(Amount is between <1000 & >2000 and Year = MaxYear-1) then "Period2"...
Sample :
Period= IF(Data[Amount]<=1000 && YEAR(Data[Date])=(MAX('Date'[Year]))),
IF(Data[Amount]<=1000 && Data[Amount]<2001 && YEAR(Data[Date])=(MAX('Date'[Year])-1)),"<1" endif BLANK()))))
Thanks,
R_
8 Replies
- MFelixSuper User
Hi R_,
The best way is to use a SWITCH function something like this:
Period = SWITCH ( TRUE (), SUM ( Table[Amount] ) <= 1000 && Date[Year] = MAX ( Date[Year] ), "Period", SUM ( Table[Amount] ) < 1000 && Date[Year] = MAX ( Date[Year] ) - 1, "Period1", SUM ( Table[Amount] ) < 1000 && SUM ( Table[Amount] ) > 1000 && Date[Year] = MAX ( Date[Year] ), "Period2", ..., "ALL PERIOD" )Regards,
MFelix
- R_Regular Visitor
Hi ,
Period = SWITCH ( TRUE (), SUM ( Table[Amount] ) <= 1000 && Date[Year] = MAX ( Date[Year]), "Period",SUM ( Table[Amount] ) < 1000 && Date[Year] = MAX ( Date[Year] ) - 1, "Period1", SUM ( Table[Amount] ) < 1000 && SUM ( Table[Amount] ) > 1000 && Date[Year] = MAX ( Date[Year] ), "Period2",Hi Plz chk my requirement once again..
If (Amount is <=1000 and Year is MaxYear) ,
If(Amount is between <1000 and Year = MaxYear-1) then "Period1" ,
If(Amount is between <1000 & >2000 and Year = MaxYear-1) then "Period2"...
If (Amount is <=1000 and Year is MaxYear) ::: this is common for period1 & period2..
Thanks,
- R_Regular Visitor
I have created period logic but if not showing elements. PF pbix file for details.
https://www.dropbox.com/s/uji1sv4dcfuprhv/period.pbix?dl=0
Thanks,
R_
- bsasPost Patron
Hi R_
In this case your requremens still are not clear for me. I've changed formula but based on yuor data only period1 can be reached or blank.
Bucket = IF(and(Data[Amount] <= 1000, Data[year] = MAX(Data[year])-1),"period1",IF(and(Data[Amount] <= 1000, and(Data[Amount] >= 2000, Data[year] = MAX(Data[year])-1)),"period2",BLANK()))