Showing results for 
Search instead for 
Did you mean: 
Advocate II
Advocate II

DAX interpreter BUG!!!

The following (code in red) works when run in the Power Bi Desktop version, but as soon as you replace it by the variable name, which contains the same code, Power BI generates an error.  In a nutshell, the column [UnreachableSince] is of data type TEXT containing textual representations of DATETIME values and other non-datetime values (I know and there is nothing I can do about this).

To intercept the DATETIME values, therefore an IF() is used.  It all works fine until you decide to use the variable name in place of the inline code inside the nested IF().

So this OK:

DATEDIFF(DATEVALUE([UnreachableSince]) + TIMEVALUE([UnreachableSince]), [ClosedDT], SECOND)

But this NOT OK!

DATEDIFF(__unreachable_dt, [ClosedDT], SECOND),


Code here (sorry but can't add colors when using Insert/Edit code sample from this editor toolbar):


"DownTime", IF ( [ErrorCategory] == "Unreachable",
                         VAR __unreachable_dt = DATEVALUE([UnreachableSince]) + TIMEVALUE([UnreachableSince])
                         VAR __unreachable_dt_in_secs = DATEDIFF(__start_date, __unreachable_dt, SECOND)
                               IF( __unreachable_dt_in_secs >= 0,
                                     DATEDIFF(DATEVALUE([UnreachableSince]) + TIMEVALUE([UnreachableSince]), [ClosedDT], SECOND),
                                     BLANK() //DATEDIFF([CreationDT], [ClosedDT], SECOND)
                          DATEDIFF([CreationDT], [ClosedDT], SECOND)
"DownTime", SUMX(CURRENTGROUP(), [DownTime])
"% up", 1 - ([DownTime] / __in_service_time)

So am I imagining things, or isn't this a DAX interpreter bug?

Advocate II
Advocate II

PBI Desktop vs = July 2022

Hi, @Element115 

Although variables can be used anywhere, however, their result might not be always the same. Because they are evaluated in the context in which they are written. 

Please refer to this thread for more details.

Caution When Using Variables in DAX and Power BI 


Best Regards,
Community Support Team _ Eason



Helpful resources

August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors