I need help in writing a DAX calculated column to get running sum which resets on particular conditions. sample data is as below:
Created Date Index clean trigger machine type counter Comments
05/01/2019 15:06:47 | 1 | 1 | 1 | 1 | 1 | clean trigger + type change resets the counter to 1 |
05/01/2019 17:38:16 | 2 | 0 | 1 | 0 | 1 | counter is maintained at previous calculation when trigger and type are 0 |
05/01/2019 22:01:27 | 3 | 0 | 1 | 0 | 1 | |
06/01/2019 03:13:07 | 4 | 0 | 1 | 0 | 1 | |
06/01/2019 06:44:09 | 5 | 0 | 1 | 0 | 1 | |
06/01/2019 08:02:39 | 6 | 0 | 1 | 0 | 1 | |
06/01/2019 10:58:31 | 7 | 0 | 1 | 1 | 2 | alone change in type triggers increment in counter |
06/01/2019 11:32:06 | 8 | 0 | 1 | 0 | 2 | |
06/01/2019 14:48:30 | 9 | 0 | 1 | 0 | 2 | |
06/01/2019 19:26:21 | 10 | 0 | 1 | 0 | 2 | |
06/01/2019 21:07:37 | 11 | 1 | 1 | 1 | 1 | clean trigger + type change resets the counter to 1 |
06/01/2019 22:01:41 | 12 | 0 | 1 | 1 | 2 | |
06/01/2019 23:09:44 | 13 | 0 | 1 | 0 | 2 | |
07/01/2019 02:03:59 | 14 | 0 | 1 | 1 | 3 | alone change in type triggers increment in counter |
07/01/2019 02:37:54 | 15 | 0 | 1 | 0 | 3 | |
07/01/2019 07:27:37 | 16 | 0 | 1 | 0 | 3 | |
07/01/2019 12:39:22 | 17 | 1 | 1 | 1 | 1 | |
07/01/2019 13:20:19 | 18 | 0 | 1 | 0 | 1 | |
07/01/2019 13:42:59 | 19 | 0 | 1 | 0 | 1 | |
07/01/2019 17:00:16 | 20 | 0 | 1 | 1 | 2 | |
07/01/2019 17:20:32 | 21 | 0 | 1 | 0 | 2 | |
07/01/2019 22:25:01 | 22 | 0 | 1 | 0 | 2 | |
08/01/2019 05:07:33 | 23 | 0 | 1 | 0 | 2 | |
08/01/2019 05:12:25 | 24 | 0 | 1 | 0 | 2 | |
08/01/2019 08:46:19 | 25 | 0 | 2 | 1 | 1 | now there is machine change also present, trigger is not present |
08/01/2019 09:02:42 | 26 | 0 | 2 | 0 | 1 | |
08/01/2019 10:18:31 | 27 | 0 | 2 | 0 | 1 | |
08/01/2019 15:29:39 | 28 | 0 | 2 | 0 | 1 | |
08/01/2019 18:29:02 | 29 | 0 | 2 | 0 | 1 | |
08/01/2019 19:16:47 | 30 | 0 | 2 | 0 | 1 | |
08/01/2019 19:46:35 | 31 | 0 | 2 | 1 | 2 | |
08/01/2019 22:14:24 | 32 | 0 | 2 | 0 | 2 | |
08/01/2019 22:50:52 | 33 | 0 | 2 | 0 | 2 | |
09/01/2019 05:33:32 | 34 | 0 | 2 | 0 | 2 | |
09/01/2019 09:04:43 | 35 | 1 | 2 | 1 | 1 | |
09/01/2019 10:03:37 | 36 | 0 | 2 | 1 | 2 | |
09/01/2019 10:44:10 | 37 | 0 | 2 | 0 | 2 | |
09/01/2019 14:10:18 | 38 | 0 | 2 | 1 | 3 | |
09/01/2019 14:38:07 | 39 | 0 | 2 | 0 | 3 | |
09/01/2019 20:47:29 | 40 | 0 | 2 | 0 | 3 | |
10/01/2019 00:18:21 | 41 | 1 | 2 | 1 | 1 | |
10/01/2019 01:07:44 | 42 | 0 | 2 | 0 | 1 | |
10/01/2019 01:30:54 | 43 | 0 | 2 | 0 | 1 | |
10/01/2019 06:15:20 | 44 | 0 | 2 | 1 | 2 | |
10/01/2019 10:01:45 | 45 | 0 | 2 | 0 | 2 | |
10/01/2019 14:40:09 | 46 | 0 | 2 | 0 | 2 | |
10/01/2019 16:10:05 | 47 | 0 | 2 | 0 | 2 | |
10/01/2019 18:51:48 | 48 | 0 | 2 | 0 | 2 |
Clean trigger resets counter to 1, and very incidence of type=1 increments counter to +1. If there are trigger and type are 0, they keep counter at last calculated value. As a main group, machine column is there, for each machine, the above calculation is executed independently.
I know to use VAR and countx related formulae to calculate running sum which filters the limited rows and then counts/sums to get the running sum, but here filtering trigger column does not make sense as I need to filter just last occurrence of trigger=1. I think, FIRSTNONBLANK kind of function be of help here, but I am unable to get it well.
Please advise.