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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
ld17
Helper II
Helper II

Calculating the number of days since last incident using DATEDIFF?

I have some incident data, and I need to count the number of days since any of the following have occurred: first aid, recordable, and lost time. I would like to use a card to display the total number of days since any of these have occurred. There are some incidents in the column, such as near misses, that I do not want to count. Basically I would like the first aids, recordables, and lost times to be aggregated so that if any of them occur, the total safe days reset to zero. My understanding is that I can use a DAX expression using DATEDIFF, but I can only figure out how to count the days between one value, not all three.

 

Ultimately, I want to have one count for maintenance "safe days" and another count for construction "safe days." I have some sample data shown below to demonstrate the columns I have.

 

Sample data.PNG

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@ld17 Maybe:

Measure =
  VAR __Today = TODAY()
  VAR __Last = MAX('Table'[Date of Incident])
RETURN
  ( __Today - __Last ) * 1.

@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@ld17 Maybe:

Measure =
  VAR __Today = TODAY()
  VAR __Last = MAX('Table'[Date of Incident])
RETURN
  ( __Today - __Last ) * 1.

@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Thank you for this! While this gives me the number of days since the last incident overall, I am still having trouble figuring out how to narrow it down to only the criteria I need (first aids, recordables, and lost times) and not just every incident that gets inputted on our log. I also only need it for the two departments: maintenance and construction.

@ld17 Well generally that would be done by putting your columns for that into some kind of visualization and thereby filtering the underlying table. But, you could also use MAXX(FILTER(...),...) when getting your __Last and thus hard code your filtering criteria if necessary.


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Ah, that makes sense. I was being dumb and overthinking that. That works. Thanks so much!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors