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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
ArchStanton
Post Prodigy
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 (
        ISBLANK ( 'Cases'[formofauthorityreceiveddate] ),
        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
jdbuchanan71
Super User
Super User

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

jdbuchanan71_1-1692365439029.png

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().

 

View solution in original post

Hi @ArchStanton 

 

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 (
        ISBLANK ( 'Cases'[formofauthorityreceiveddate] ),
        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

View solution in original post

3 REPLIES 3
jdbuchanan71
Super User
Super User

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

jdbuchanan71_1-1692365439029.png

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().

 

Hi @ArchStanton 

 

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 (
        ISBLANK ( 'Cases'[formofauthorityreceiveddate] ),
        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

Really grateful for your reply as well, many thanks

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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