Convert a metric breakdown into a KPI
Sometimes the most interesting KPIs that you can created come from the metadata rather than the numeric metric or KPI value. This is especially true when it is important to compare the proportion of one breakdown value to another. For example, if we collect a metric for the number of unresolved issues why might choose to a breakdown for this metric of Priority. A useful KPI that can be calculated from this metric is the % of unresolved high priority issues.
On line 2 as before we use the variable metrics to get the last known value for the metric using the wild card expression: *unresolved*
On line 5 we add some defensive coding to check that values are available for the date of the calculation
On line 8 get the breakdown metadata for the unresolved issues
On line 9 we have more defensive coding
On line 12 we get the priority breakdown and convert it to % values
On line 15 remove all low priority values from the priority breakdown
On line 18 return the sum of all remain priority breakdown values as the value for the KPI