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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Count Days Since last OSHA Incident

Hello, 

 

I'm stumped. I need help creating a count of days between "Yes" recordable events, and count of days since our most recent "Yes" OSHA Recordable. 

 

Date of IncidentIncident TypeOSHA Recordable
01/20/2019InjuryYES
3/14/2019InjuryNO
4/12/2019Near HitNO

4/25/2019

InjuryYES

 

Thank you in advance! 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Anonymous 

In this case, I would suggest you to create a column instead of a measure. See my sample below, hope it makes sense for you.

column countdays since last yes.JPG

count since last yes =
IF (
    Sheet6[OSHA Recordable] = "Yes",
    DATEDIFF (
        CALCULATE (
            MAX ( [Date of Incident] ),
            FILTER ( Sheet6, [Date of Incident] < EARLIER ( Sheet6[Date of Incident] ) ),
            FILTER ( Sheet6, [OSHA Recordable] = "Yes" )
        ),
        [Date of Incident],
        DAY
    ),
    BLANK ()
)

 

Best,
Paul

View solution in original post

5 REPLIES 5
Nathaniel_C
Community Champion
Community Champion

Hi @Anonymous ,
Try this:

Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

Date Diff =
VAR _currDate =
    MAX ( injTable[Date of Incident] )
VAR _pastDate =
    CALCULATE (
        MAX ( injTable[Date of Incident] ),
        ALLEXCEPT ( injTable, injTable[OSHA Recordable] ),
        injTable[Date of Incident] < _currDate
    )
RETURN
    IF (
        MAX ( injTable[OSHA Recordable] ) = "YES",
        DATEDIFF ( _pastDate, _currDate, DAY )
    )


osha.PNG

 


 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Hi,  

I assumed that your data has more than just the 4 rows. Basically you use DATEDIFF function:

1. Count days between the last yes and the second last yes 

 

1. Count days between the last yes and the second last yes 
Countdays between two Yes = 
var Lastyes = CALCULATE(LASTDATE(Sheet5[Date of Incident]),
                    FILTER(Sheet5,[OSHA Recordable]="YES"))

var Seclastyes = CALCULATE(LASTDATE(Sheet5[Date of Incident]),
                    FILTER(Sheet5,[Date of Incident]<Lastyes),
                        FILTER(Sheet5,[OSHA Recordable]="YES"))

Return DATEDIFF(Seclastyes,Lastyes,DAY)

 

2. Count days between the last yes and now.

 

Countdays since recent yes = 
var Lastyes = CALCULATE(LASTDATE(Sheet5[Date of Incident]),
                 FILTER(Sheet5,[OSHA Recordable]="YES"))

Return DATEDIFF([01Lastyes],NOW(),DAY)

 

There is the pbix if needed.

https://qiuyunus-my.sharepoint.com/:u:/g/personal/paul_qiuyunus_onmicrosoft_com/ERdc7wQicIhEr9oL-2i5...

Best, 
Paul

Anonymous
Not applicable

Hello Paul, 

 

Thank you very much for this! When I plugged these in the "countdays between two yes" it only gives me the number of days between the last two OSHA recordables of the month. How could I expand this DAX to count every day between every yes? Again, thank you @Anonymous !

 

2018Count of OSHA RecordableCountdays between two Yes
March37
11 
221 
291 
April211
121 
231 
Anonymous
Not applicable

@Anonymous 

In this case, I would suggest you to create a column instead of a measure. See my sample below, hope it makes sense for you.

column countdays since last yes.JPG

count since last yes =
IF (
    Sheet6[OSHA Recordable] = "Yes",
    DATEDIFF (
        CALCULATE (
            MAX ( [Date of Incident] ),
            FILTER ( Sheet6, [Date of Incident] < EARLIER ( Sheet6[Date of Incident] ) ),
            FILTER ( Sheet6, [OSHA Recordable] = "Yes" )
        ),
        [Date of Incident],
        DAY
    ),
    BLANK ()
)

 

Best,
Paul

Anonymous
Not applicable

Awesome this is great, thank you so much!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.