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
magnificentnile
Regular Visitor

Date Diff Question using IF and ISBLANK

I have 2 columns

one vRTT[DateInPublishing 

vRTT[DateOutOfPublishing]

 

If vRTT[DateOutOfPublishing] ISBLANK I would like DateDiff to calculate based on TODAY() otherwise it would calculate the datediff between the In and Out fields. 

 

I thought something like the following woud work...

 

WIPLayout = DATEDIFF(vRTT[DateInPublishing],
(IF(ISBLANK(vRTT[DateOutOfPublishing]), TODAY(), vRTT[DateOutOfPublishing])),
vRTT[DateOutOfPublishing],DAY)

1 ACCEPTED SOLUTION

Okay I think we got this - test it to make sure Smiley Happy

 

WIPLayout =
IF (
    ISBLANK ( vRTT[DateOutOfPublishing] ),
    SWITCH (
        TRUE (),
        TODAY () > vRTT[DateInPublishing], DATEDIFF ( vRTT[DateInPublishing], TODAY (), DAY ),
        TODAY () < vRTT[DateInPublishing], DATEDIFF ( TODAY (), vRTT[DateInPublishing], DAY ) * -1,
        0
    ),
    SWITCH (
        TRUE (),
        vRTT[DateOutOfPublishing] > vRTT[DateInPublishing], DATEDIFF ( vRTT[DateInPublishing], vRTT[DateOutOfPublishing], DAY ),
        vRTT[DateOutOfPublishing] < vRTT[DateInPublishing], DATEDIFF ( vRTT[DateOutOfPublishing], vRTT[DateInPublishing], DAY ) * -1,
        0
    )
)

 

EDIT:

So if the "OutOf" or "published" date is blank

The first SWITCH checks whether the "In" or "submitted" date is so to speak in the future i.e. > today

this is what throws off the error (those results will be negative * -1)

 

The second SWITCH checks whether it could have been "published" before it was ever "submitted"

again those results will be negative

 

Hope this makes sense!

View solution in original post

4 REPLIES 4
Sean
Community Champion
Community Champion

WIPLayout =
IF (
    ISBLANK ( vRTT[DateOutOfPublishing] ),
    DATEDIFF ( vRTT[DateInPublishing], TODAY (), DAY ),
    DATEDIFF ( vRTT[DateInPublishing], vRTT[DateOutOfPublishing], DAY )
)

Supplental question:

 

WIPapproval = DATEDIFF(vRTT[DateOutOfPublishing], (IF(ISBLANK(vRTT[PublishedDate]), TODAY(), vRTT[PublishedDate])), DAY) 

 

returns an error:

In DATEDIFF function, the start date cannot be greater than the end date

 

How would I put an IF statement in front to capture the situations where the DATEDIFF throws the error?

Okay I think we got this - test it to make sure Smiley Happy

 

WIPLayout =
IF (
    ISBLANK ( vRTT[DateOutOfPublishing] ),
    SWITCH (
        TRUE (),
        TODAY () > vRTT[DateInPublishing], DATEDIFF ( vRTT[DateInPublishing], TODAY (), DAY ),
        TODAY () < vRTT[DateInPublishing], DATEDIFF ( TODAY (), vRTT[DateInPublishing], DAY ) * -1,
        0
    ),
    SWITCH (
        TRUE (),
        vRTT[DateOutOfPublishing] > vRTT[DateInPublishing], DATEDIFF ( vRTT[DateInPublishing], vRTT[DateOutOfPublishing], DAY ),
        vRTT[DateOutOfPublishing] < vRTT[DateInPublishing], DATEDIFF ( vRTT[DateOutOfPublishing], vRTT[DateInPublishing], DAY ) * -1,
        0
    )
)

 

EDIT:

So if the "OutOf" or "published" date is blank

The first SWITCH checks whether the "In" or "submitted" date is so to speak in the future i.e. > today

this is what throws off the error (those results will be negative * -1)

 

The second SWITCH checks whether it could have been "published" before it was ever "submitted"

again those results will be negative

 

Hope this makes sense!

Thank you very much!

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.