Using Aggr to calculate percentage, excluding some values
My data looks like this:
Date
Machine
Event_Class
Duration
Duration_Percent
1/1/2020
ABC123
Downtime
20
1/1/2020
ABC123
Downtime
15
1/1/2020
ABC123
Uptime
50
0.625
1/1/2020
ABC123
LowPerformance
30
0.375
1/1/2020
XYZ789
Unrelated
25
1/1/2020
XYZ789
Uptime
60
0.4
1/1/2020
XYZ789
LowPerformance
20
0.133
1/1/2020
XYZ789
LowPerformance
30
0.2
1/1/2020
XYZ789
Unavailable
40
0.267
1/2/2020
ABC123
Unrelated
15
1/2/2020
ABC123
Uptime
30
0.3
1/2/2020
ABC123
LowPerformance
20
0.2
1/2/2020
ABC123
LowPerformance
30
0.3
1/2/2020
ABC123
Unavailable
10
0.1
1/2/2020
ABC123
Unavailable
10
0.1
My end result is two different stacked bar graphs that will both be stacked by date and will only display if one machine is selected at a time (I got that part handled by the calculation condition).
The first graph works fine because it is just the sum of the duration of the events on a day, stacked by their "Event_Class":
The second graph I'm having an issue with - I want to see the values of the "Event_Class" stacks in percentages instead of by the values, however, I want to exclude values where Event_Class = 'Downtime' or 'Unrelated' from the denominator of the percentage calculation so that the stacks will always be 100%. I worked around this by doing the percentage calculation of the events in the load script, however I have a new requirement that the user wants to be able to use the alternative dimension selector to change it from the date to the week, month, or year (so using my Duration_Percent column to average it over the amount of days won't work since that number is a percentage of that day's total duration of applicable Event_Class events. Below is what the intended output would look like: