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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
JoaoSifredo
Frequent Visitor

Calculating running days without a accident

Hello community, I need help with a health safety dashboard at work.

I can't calculate accident-free days.

I have a table of accident records, you can see it below:

I want to calculate the accumulated number of days without accidents if it is an "AT" accident.

 

DataTipo de Evento
06/01/2023AT
11/01/2023AT
15/01/2023AT
09/01/2023PS
26/01/2023PS
27/01/2023PS
27/01/2023PS
31/01/2023PS
05/01/2023QA
16/01/2023QA
25/01/2023PS
17/01/2023QA
16/01/2023QA
24/01/2023QA
1 ACCEPTED SOLUTION
Dangar332
Super User
Super User

hi, @JoaoSifredo 


try below measure

 

Measure 2 = 
var a = CALCULATE(MIN('Table (2)'[Data]),FILTER(ALL('Table (2)'),'Table (2)'[Tipo de Evento]="at"))
RETURN
SUMX(
    FILTER( 
        'Table (2)',
        [Tipo de Evento]="at" &&
        [Data]<=MAX([Data])
    ),
    DATEDIFF(a,MIN('Table (2)'[Data]),DAY)
)

 

Dangar332_0-1704651180486.png

 

 

View solution in original post

3 REPLIES 3
JoaoSifredo
Frequent Visitor

Hi @Dangar332 

Thank you very much for your solution, however I found a solution, which is not perfect. It is not calculating before the first event. How can you see.

 

JoaoSifredo_2-1704660851549.png

 

 

hi, @JoaoSifredo 

 

in your var data _anteior_acidente  you count previous data of  Tipo de Evento="AT" of current date of "at"

means currentdate :15/01/2023  and  var data _anteior_acidente is calculate its previous value of "at" that is 11/1/2023

 

update  var data _anteior_acidente =
calculate(
     min(tablename[data]),
     tablename[data]<=data_currente,
     tablename[tipo de evento]="at"
  ) 

 

you get your answer

 

Dangar332
Super User
Super User

hi, @JoaoSifredo 


try below measure

 

Measure 2 = 
var a = CALCULATE(MIN('Table (2)'[Data]),FILTER(ALL('Table (2)'),'Table (2)'[Tipo de Evento]="at"))
RETURN
SUMX(
    FILTER( 
        'Table (2)',
        [Tipo de Evento]="at" &&
        [Data]<=MAX([Data])
    ),
    DATEDIFF(a,MIN('Table (2)'[Data]),DAY)
)

 

Dangar332_0-1704651180486.png

 

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.