cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Post Prodigy

## Help with evaluating some DAX code

Hi,

I'm struggling to work out how this piece of code is being being evaluated, in particular what is being calculated first, second and so on. If some could break it down to show what each step is in order it would be a great help.

Also, Is there a way of making this code simpler using Variables?

``````Days ERT to Outcome =
IF (
NOT ( ISBLANK ( 'Cases'[ERT Start FlagDate] )),
IF (
DATEDIFF (
IF (
'Cases'[Created Date] > 'Cases'[ERT Start FlagDate],
'Cases'[Created on],
'Cases'[ERT Start FlagDate]
),
IF ( ISBLANK ( 'Cases'[ERT End FlagDate] ), NOW (), 'Cases'[ERT End FlagDate] ),
DAY
),
DATEDIFF ( 'Cases'[ERT Start FlagDate], 'Cases'[ERT End FlagDate], DAY )
),
BLANK ()
)``````

Thanks,

2 ACCEPTED SOLUTIONS
Super User

IF statements work from the top in so it check 1, the 2 etc:

It startts with 1 and IF 'Cases[ERT Start Flag Date] is not blank it goes to section A which starts the 2 check, if it is blank it gos to B and returns a BLANK().

Super User

The explanation from @jdbuchanan71 is perfect. Regarding your second question, you can use variables in this way:

``````Days ERT to Outcome =

var _startFlag= ISBLANK ( 'Cases'[ERT Start FlagDate] )
var _endFlag= ISBLANK ( 'Cases'[ERT End FlagDate] )

IF (
NOT ( _startFlag),
IF (
DATEDIFF (
IF (
'Cases'[Created Date] > 'Cases'[ERT Start FlagDate],
'Cases'[Created on],
'Cases'[ERT Start FlagDate]
),
IF ( _endFlag , NOW (), 'Cases'[ERT End FlagDate] ),
DAY
),
DATEDIFF ( 'Cases'[ERT Start FlagDate], 'Cases'[ERT End FlagDate], DAY )
),
BLANK ()
)``````

However, as you can see, it doesn't make much sense. Variables avoid repetitive calculus, but in this case, you don't have repetitive pieces

3 REPLIES 3
Super User

IF statements work from the top in so it check 1, the 2 etc:

It startts with 1 and IF 'Cases[ERT Start Flag Date] is not blank it goes to section A which starts the 2 check, if it is blank it gos to B and returns a BLANK().

Super User

The explanation from @jdbuchanan71 is perfect. Regarding your second question, you can use variables in this way:

``````Days ERT to Outcome =

var _startFlag= ISBLANK ( 'Cases'[ERT Start FlagDate] )
var _endFlag= ISBLANK ( 'Cases'[ERT End FlagDate] )

IF (
NOT ( _startFlag),
IF (
DATEDIFF (
IF (
'Cases'[Created Date] > 'Cases'[ERT Start FlagDate],
'Cases'[Created on],
'Cases'[ERT Start FlagDate]
),
IF ( _endFlag , NOW (), 'Cases'[ERT End FlagDate] ),
DAY
),
DATEDIFF ( 'Cases'[ERT Start FlagDate], 'Cases'[ERT End FlagDate], DAY )
),
BLANK ()
)``````

However, as you can see, it doesn't make much sense. Variables avoid repetitive calculus, but in this case, you don't have repetitive pieces

Post Prodigy

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - June 2024

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

#### Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors
Top Kudoed Authors