Forum Discussion
Running total with different column condition
Hi guys i have this data :
| TIMESTAMP_INIZIO_ARR | TIMESTAMP_FINE_ARR | INSMAN | TURNO | value |
| 2024-05-04 05:30:00.000 | 2024-05-04 06:00:00.000 | 1 | 1 | 926 |
| 2024-05-04 06:00:00.000 | 2024-05-04 06:30:00.000 | 1 | 1 | 2305 |
| 2024-05-04 06:30:00.000 | 2024-05-04 07:00:00.000 | 1 | 1 | 0 |
| 2024-05-04 07:00:00.000 | 2024-05-04 07:30:00.000 | 1 | 1 | 2214 |
| 2024-05-04 07:30:00.000 | 2024-05-04 08:00:00.000 | 1 | 1 | 2779 |
| 2024-05-04 08:00:00.000 | 2024-05-04 08:30:00.000 | 1 | 1 | 3163 |
| 2024-05-04 08:30:00.000 | 2024-05-04 09:00:00.000 | 1 | 1 | 2960 |
| 2024-05-04 09:00:00.000 | 2024-05-04 09:30:00.000 | 1 | 1 | 3141 |
| 2024-05-04 09:30:00.000 | 2024-05-04 10:00:00.000 | 1 | 1 | 3141 |
| 2024-05-04 10:00:00.000 | 2024-05-04 10:30:00.000 | 1 | 1 | 2983 |
| 2024-05-04 10:30:00.000 | 2024-05-04 11:00:00.000 | 1 | 1 | 1649 |
| 2024-05-04 11:00:00.000 | 2024-05-04 11:30:00.000 | 1 | 1 | 3141 |
| 2024-05-04 11:30:00.000 | 2024-05-04 12:00:00.000 | 1 | 1 | 2937 |
| 2024-05-04 12:00:00.000 | 2024-05-04 12:30:00.000 | 1 | 1 | 1717 |
| 2024-05-04 12:30:00.000 | 2024-05-04 13:00:00.000 | 1 | 1 | 0 |
| 2024-05-04 13:00:00.000 | 2024-05-04 13:30:00.000 | 1 | 1 | 1175 |
| 2024-05-04 13:30:00.000 | 2024-05-04 14:00:00.000 | 1 | 2 | 3163 |
| 2024-05-04 14:00:00.000 | 2024-05-04 14:30:00.000 | 1 | 2 | 3118 |
| 2024-05-04 14:30:00.000 | 2024-05-04 15:00:00.000 | 1 | 2 | 2983 |
| 2024-05-04 15:00:00.000 | 2024-05-04 15:30:00.000 | 1 | 2 | 3141 |
| 2024-05-04 15:30:00.000 | 2024-05-04 16:00:00.000 | 1 | 2 | 2983 |
| 2024-05-04 16:00:00.000 | 2024-05-04 16:30:00.000 | 1 | 2 | 3005 |
| 2024-05-04 16:30:00.000 | 2024-05-04 17:00:00.000 | 1 | 2 | 3412 |
| 2024-05-04 17:00:00.000 | 2024-05-04 17:30:00.000 | 1 | 2 | 3141 |
| 2024-05-04 17:30:00.000 | 2024-05-04 18:00:00.000 | 1 | 2 | 2757 |
| 2024-05-04 18:00:00.000 | 2024-05-04 18:30:00.000 | 1 | 2 | 3163 |
| 2024-05-04 18:30:00.000 | 2024-05-04 19:00:00.000 | 1 | 2 | 2960 |
| 2024-05-04 19:00:00.000 | 2024-05-04 19:30:00.000 | 1 | 2 | 2779 |
| 2024-05-04 19:30:00.000 | 2024-05-04 20:00:00.000 | 1 | 3 | 3163 |
| 2024-05-04 20:00:00.000 | 2024-05-04 20:30:00.000 | 1 | 3 | 1853 |
| 2024-05-04 20:30:00.000 | 2024-05-04 21:00:00.000 | 1 | 3 | 0 |
| 2024-05-04 21:00:00.000 | 2024-05-04 21:30:00.000 | 1 | 3 | 0 |
| 2024-05-04 21:30:00.000 | 2024-05-04 22:00:00.000 | 1 | 3 | 429 |
| 2024-05-04 22:00:00.000 | 2024-05-04 22:30:00.000 | 1 | 3 | 1898 |
| 2024-05-04 22:30:00.000 | 2024-05-04 23:00:00.000 | 1 | 3 | 3163 |
| 2024-05-04 23:00:00.000 | 2024-05-04 23:30:00.000 | 1 | 3 | 3118 |
| 2024-05-04 23:30:00.000 | 2024-05-05 00:00:00.000 | 1 | 3 | 3163 |
| 2024-05-05 00:00:00.000 | 2024-05-05 00:30:00.000 | 1 | 3 | 2824 |
| 2024-05-05 00:30:00.000 | 2024-05-05 01:00:00.000 | 1 | 3 | 3141 |
| 2024-05-05 01:00:00.000 | 2024-05-05 01:30:00.000 | 1 | 3 | 2870 |
| 2024-05-05 01:30:00.000 | 2024-05-05 02:00:00.000 | 1 | 3 | 2485 |
| 2024-05-05 02:00:00.000 | 2024-05-05 02:30:00.000 | 1 | 3 | 926 |
| 2024-05-05 02:30:00.000 | 2024-05-05 03:00:00.000 | 1 | 3 | 2305 |
| 2024-05-05 03:00:00.000 | 2024-05-05 03:30:00.000 | 1 | 3 | 0 |
| 2024-05-05 03:30:00.000 | 2024-05-05 04:00:00.000 | 1 | 3 | 2214 |
| 2024-05-05 04:00:00.000 | 2024-05-05 04:30:00.000 | 1 | 3 | 2779 |
| 2024-05-05 04:30:00.000 | 2024-05-05 05:00:00.000 | 1 | 3 | 3163 |
| 2024-05-05 05:00:00.000 | 2024-05-05 05:30:00.000 | 1 | 3 | 2960 |
| 2024-05-05 05:30:00.000 | 2024-05-05 06:00:00.000 | 1 | 1 | 3141 |
| 2024-05-05 06:00:00.000 | 2024-05-05 06:30:00.000 | 1 | 1 | 3141 |
| 2024-05-05 06:30:00.000 | 2024-05-05 07:00:00.000 | 1 | 1 | 2983 |
| 2024-05-05 07:00:00.000 | 2024-05-05 07:30:00.000 | 1 | 1 | 1649 |
| 2024-05-05 07:30:00.000 | 2024-05-05 08:00:00.000 | 1 | 1 | 3141 |
| 2024-05-05 08:00:00.000 | 2024-05-05 08:30:00.000 | 1 | 1 | 2937 |
| 2024-05-05 08:30:00.000 | 2024-05-05 09:00:00.000 | 1 | 1 | 1717 |
| 2024-05-05 09:00:00.000 | 2024-05-05 09:30:00.000 | 1 | 1 | 0 |
| 2024-05-05 09:30:00.000 | 2024-05-05 10:00:00.000 | 1 | 1 | 1175 |
| 2024-05-05 10:00:00.000 | 2024-05-05 10:30:00.000 | 1 | 1 | 3163 |
| 2024-05-05 10:30:00.000 | 2024-05-05 11:00:00.000 | 1 | 1 | 3118 |
| 2024-05-05 11:00:00.000 | 2024-05-05 11:30:00.000 | 1 | 1 | 2983 |
| 2024-05-05 11:30:00.000 | 2024-05-05 12:00:00.000 | 1 | 1 | 3141 |
| 2024-05-05 12:00:00.000 | 2024-05-05 12:30:00.000 | 1 | 1 | 2983 |
| 2024-05-05 12:30:00.000 | 2024-05-05 13:00:00.000 | 1 | 1 | 3005 |
| 2024-05-05 13:00:00.000 | 2024-05-05 13:30:00.000 | 1 | 1 | 3412 |
i have to calculate the cumulative sum based on the "turno " column , so every time the shift changes i have to reset the cumulative sum to zero and restart, i also have the day as a parameter, but the column turno changes even betweem one day and another, i honestly don't know how to do it
- Anonymous2 years ago
Hi, jc173
First, you need to create an Index, which can be created by selecting AddColumn in PowerQuery.
Apply and close. Then create a calculated column.
Cumulative Sum = VAR CurrentTurno = 'Table'[TURNO] RETURN CALCULATE( SUM('Table'[value]), FILTER( ALL('Table'), 'Table'[Index] <= EARLIER('Table'[Index]) && 'Table'[TURNO] = CurrentTurno ) )Here is my preview:
How to Get Your Question Answered Quickly
Best Regards
Yongkang Hua
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- AnonymousNot applicable
Hi, jc173
First, you need to create an Index, which can be created by selecting AddColumn in PowerQuery.
Apply and close. Then create a calculated column.
Cumulative Sum = VAR CurrentTurno = 'Table'[TURNO] RETURN CALCULATE( SUM('Table'[value]), FILTER( ALL('Table'), 'Table'[Index] <= EARLIER('Table'[Index]) && 'Table'[TURNO] = CurrentTurno ) )Here is my preview:
How to Get Your Question Answered Quickly
Best Regards
Yongkang Hua
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Ashish_MathurSuper User
Hi,
In another column, show the expected result very clearly.