Forum Discussion
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.
| Data | Tipo de Evento |
| 06/01/2023 | AT |
| 11/01/2023 | AT |
| 15/01/2023 | AT |
| 09/01/2023 | PS |
| 26/01/2023 | PS |
| 27/01/2023 | PS |
| 27/01/2023 | PS |
| 31/01/2023 | PS |
| 05/01/2023 | QA |
| 16/01/2023 | QA |
| 25/01/2023 | PS |
| 17/01/2023 | QA |
| 16/01/2023 | QA |
| 24/01/2023 | QA |
hi, Anonymous
try below measureMeasure 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) )
3 Replies
- Dangar332
Resident Rockstar
hi, Anonymous
try below measureMeasure 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) ) - AnonymousNot applicable
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.
- Dangar332
Resident Rockstar
hi, Anonymous
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