How to calculate unique count across time in expression


#1

Is there a way to calculate unique count across time in metric expression? E.g. if my base metric returns [0, 1, 1, 2, 2, 0, 0], then uniqueCount() should return an identity timeseries of 3 (3 unique values)


#2

just a hint, you can try with rollingDiff and then wrap it inside a an aggregate, e.g.

aggregate(rollingDiff(<your-metric>), 'SUM')

Update this will calculate the count of sequences as in your example, but will give incorrect values if you need to consider this example: 0, 0, 1, 1, 0, 2 …


#3

How can that compute the number of unique values?


#4

@alex.ding AFAIK, there isn’t a function like that today, but feel free to add a MetricFunctionLibrary function to compute that. See Metric referencing actionDecl-based metric returns empty timeseries