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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
NRW_admin1
New Member

Nested IF and DATEDIFF formulas when some date fields are blank

I would like to count the number of days between two date fields: 'datereceived' and 'datedulymade'. I tried to use the DATEDIFF function, BUT - some of the corresponding dates are the same (e.g. number of days between dates=0) which seems to cause an error, ALSO, some of the 'datedulymade' rows are blank (i.e. process not complete)

 

I have tried to nest an IF statement in to the DATEDIFF field however the blank date fields seem to be causing an error of the format type and I I am unsure how to get around this.

6 REPLIES 6
Greg_Deckler
Super User
Super User

Perhaps use ISBLANK in your IF statement to check for that boundary condition?

 

https://msdn.microsoft.com/en-us/library/ee634204.aspx

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@NRW_admin1 You can use DATEDIFF when the dates are the same (see picture below) but you can't have blanks or negative values (to deal with negatives see link at the bottom)

 

Num of Days =
IF (
    ISBLANK ( 'Table'[Made] ),
    BLANK (),
    DATEDIFF ( 'Table'[Received], 'Table'[Made], DAY )
)

 

DATEDIFF - ISBLANK.png

 

Also see response here... (although this doesn't deal with Blank may give some ideas)

http://community.powerbi.com/t5/Desktop/How-to-use-DATEDIFF-when-End-Date-is-less-than-Start-Date/m-...

Problem solved, combined with guidance in the link. Many thanks 🙂

@NRW_admin1
It is great to hear the problem got solved.

 

It would be greatly appreciated of you if  you can post the solution and accepting it as solution can help the people who would have the same problem to find the answer quickly. 🙂

To workaround the blank values in the date column, I created a new column with a false date (01/01/2025) for all the blanks:

 

false date (duly made) = IF(ISBLANK(permitapplicationSet[nrw_dulymadedate]), DATE(2025, 1, 1), permitapplicationSet[dulymadedate])

 

Then I used the formula to calculate number of days taken to duly make the applications:

 

Days to duly make = SWITCH(TRUE(), permitapplicationSet[datereceived]<permitapplicationSet[dulymadedate], DATEDIFF(permitapplicationSet[datereceived], permitapplicationSet[dulymadedate], DAY), permitapplicationSet[datereceived]>permitapplicationSet[dulymadedate], -1*DATEDIFF(permitapplicationSet[dulymadedate], permitapplicationSet[datereceived], DAY), 0)

 

This actually returned a blank for all rows with the false date. Which is great although I wasn't expecting that result!

Nhallquist
Helper V
Helper V

Can you post the formula's that you have tried?  

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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