This is best Fabric, Power BI, SQL and AI community event. How do we know? The last event sold out! Save €200 with code FABCMTY200.
Register nowA new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.
I got stucked writing Nested IF/AND statement.
Below is the statement I wrote in Excel, ref!A1 is the date 8/31/2018
=IF(V2>ref!$A$1,"Future",IF(AND(V2<=ref!$A$1, X2=0),"Late",IF(AND(V2<=ref!$A$1,X2<>0, Y2<=0),"On-Time","Late")))
This is the statement I wrote in power bi but I'm getting syntax error.
Column = IF(Data[BL Date] > date(2018,8,31) = "Future", IF(AND(Data[BL Date] <= date(2018,8,31), Data[Actual Date]<>0 = "Late"), IF(AND(Data[BL Date],Data[Actual Date]<>0),Data[Variance] <= 0),"On-Time","Late" )))
Can someone please help?
Thanks much!
Solved! Go to Solution.
The reason your formula is not working is that AND accepts only 2 arguments!
I personally prefer @MFelix's SWITCH approach using && easier to ready (for me at least)
But you could try this...
Column =
IF (
Data[BL Date] > DATE ( 2018, 8, 31 )
= "Future",
IF (
AND ( Data[BL Date] <= DATE ( 2018, 8, 31 ), Data[Actual Date] <> 0 ),
"Late",
IF (
AND ( AND ( Data[BL Date] <> 0, Data[Actual Date] <> 0 ), Data[Variance] <= 0 ),
"On-Time",
"Late"
)
)
)
@StuznetLet me know if this actually works! ![]()
EDIT: @MFelix I believe you need to add this condition...
nested if =
IF (
Data[BL Date] > DATE ( 2018, 8, 31 ),
"Future",
IF (
Data[BL Date] <= DATE ( 2018, 8, 31 )
&& Data[Actual Date] <> 0,
"Late",
IF (
Data[BL Date] <> 0
&& Data[Actual Date] <> 0
&& Data[Variance] <= 0,
"On-Time",
"Late"
)
)
)And...
SWITCH FORMULA =
SWITCH (
TRUE (),
Data[BL Date] > DATE ( 2018, 8, 31 ), "Future",
Data[BL Date] <= DATE ( 2018, 8, 31 )
&& Data[Actual Date] <> 0, "Late",
Data[BL Date] <> 0
&& Data[Actual Date] <> 0
&& Data[Variance] <= 0, "On-Time",
"Late"
)
Thank you so much for your help but the correct formula I'm looking is this. Now the result are matching.
Hi @Stuznet,
You have some incorrections on DAX IF you don't use the = to define the states also the brackets I have made some changes to reduce the DAX you can use one of both formulas below:
nested if =
IF (
Data[BL Date] > DATE ( 2018, 8, 31 ),
"Future",
IF (
Data[BL Date] <= DATE ( 2018, 8, 31 )
&& Data[Actual Date] <> 0,
"Late",
IF (
Data[BL Date] <> 0
&& Data[Actual Date] <> 0
&& Data[Variance] <= 0,
"On-Time",
"Late"
)
)
)
Rather than use the nested IF is better to use the SWITHC function check the documentation here, see below the dax formula for your case.
SWITCH FORMULA =
SWITCH (
TRUE (),
Data[BL Date] > DATE ( 2018, 8, 31 ), "Future",
Data[BL Date] <= DATE ( 2018, 8, 31 )
&& Data[Actual Date] <> 0, "Late",
Data[BL Date] <> 0
&& Data[Actual Date] <> 0
&& Data[Variance] <= 0, "On-Time",
"Late"
)
Regards,
MFelix
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsThe reason your formula is not working is that AND accepts only 2 arguments!
I personally prefer @MFelix's SWITCH approach using && easier to ready (for me at least)
But you could try this...
Column =
IF (
Data[BL Date] > DATE ( 2018, 8, 31 )
= "Future",
IF (
AND ( Data[BL Date] <= DATE ( 2018, 8, 31 ), Data[Actual Date] <> 0 ),
"Late",
IF (
AND ( AND ( Data[BL Date] <> 0, Data[Actual Date] <> 0 ), Data[Variance] <= 0 ),
"On-Time",
"Late"
)
)
)
@StuznetLet me know if this actually works! ![]()
EDIT: @MFelix I believe you need to add this condition...
nested if =
IF (
Data[BL Date] > DATE ( 2018, 8, 31 ),
"Future",
IF (
Data[BL Date] <= DATE ( 2018, 8, 31 )
&& Data[Actual Date] <> 0,
"Late",
IF (
Data[BL Date] <> 0
&& Data[Actual Date] <> 0
&& Data[Variance] <= 0,
"On-Time",
"Late"
)
)
)And...
SWITCH FORMULA =
SWITCH (
TRUE (),
Data[BL Date] > DATE ( 2018, 8, 31 ), "Future",
Data[BL Date] <= DATE ( 2018, 8, 31 )
&& Data[Actual Date] <> 0, "Late",
Data[BL Date] <> 0
&& Data[Actual Date] <> 0
&& Data[Variance] <= 0, "On-Time",
"Late"
)
Thank you so much for your help but the correct formula I'm looking is this. Now the result are matching.
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsI prefer SWITCH as well as it is easier to read and less opening and closing parentheses to keep track of.
SWITCH is internally converted into nested IFs anyway ![]()
BTW I see you added the <>0 above ![]()
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsSign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 32 | |
| 26 | |
| 21 | |
| 20 | |
| 15 |
| User | Count |
|---|---|
| 65 | |
| 43 | |
| 28 | |
| 24 | |
| 22 |