cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
anongard
Helper I
Helper I

DATEDIFF with blank dates

Hello all,

 

I'm struggling hard with the datediff function right now. My problem is this:

 

I have two columns of dates, column A is a start date and column B is a finish date. Every column has a start date, but not every column has a finish date. I am trying to create a column C that has the age of the record. Using DATEDIFF=(column A, column B, DAY) will return the age in days of the columns with an end date, but since there are null values for those still ongoing, it returns nothing for them. I still need that age! Any thoughts on how to accomplish this?  

 

Thanks,

Alex

 

 

1 ACCEPTED SOLUTION
v-yuezhe-msft
Microsoft
Microsoft

@anongard,

What days do you want to return for those blank end dates? If you want to return the days between start date and today when the end date us blank, you can use the following DAX to calculate age of the record.

Column = IF(ISBLANK(Table[End Date]),DATEDIFF(Table[Start Date],TODAY(),DAY),DATEDIFF(Table[Start Date],Table[End Date],DAY))
1.PNG


Regards,

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-yuezhe-msft
Microsoft
Microsoft

@anongard,

What days do you want to return for those blank end dates? If you want to return the days between start date and today when the end date us blank, you can use the following DAX to calculate age of the record.

Column = IF(ISBLANK(Table[End Date]),DATEDIFF(Table[Start Date],TODAY(),DAY),DATEDIFF(Table[Start Date],Table[End Date],DAY))
1.PNG


Regards,

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

hello - instead of using TODAY is there a way to calculate it from date slicer.

user2021_0-1637278970258.png

Column = IF(ISBLANK(Table[End Date]),DATEDIFF(Table[Start Date],TODAY(),DAY),DATEDIFF(Table[Start Date],Table[End Date],DAY))

 

Thank you.

 

 

 

Thank you! Related, but more difficult question:

 

In PowerQuery, I'm trying to replicate this DAX function: TestCourse = IF(Courses[CompletedDate] > Courses[ActivationDate],TRUE,FALSE)

 

However, nothing I've tried in M has worked. I tried first with

 

= if Courses[CompletedDate] > Courses[ActivationDate]

then "TRUE"

else "FALSE" 

 

but I get errors about cyclic references and nothing very helpful to resolve it. If I could sort / filter in the DAX view that would be even better, but I suppose that's the entire point... 

 

Thanks,

Alex

@anongard,

I am not able to reproduce your issue. In Query Editor, add a custom column as shown in the following screenshot.
1.PNG2.PNG

Regards,

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I was able to solve this with conditional columns, thankfully. I don't know why it worked for you though, I have literally the exact same thing typed in mine and I still get cyclic errors. Is there something that could be giving it trouble in the data? 

Helpful resources

Announcements
August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

Power BI Dev Camp Session 25 with aka link 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, August 25 at 11a PDT for a great session with Ted Pattison!

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