Program indicator for count of unique/distinct values

I’m trying to fiugre out how to create a program indicator that will report the number of unique occurences of a text data element. For example the number of unique users id’s that performed an assessment within a give period and org unit.

Is this currently possible and if so can anybody point me in the right direction?

1 Like

@gjones we would like to create a similar program indicator. We have an event program with an ID (entered as a text data value type) and want to count the total number of unique IDs entered rather than each event.

One way we are thinking about getting around this is to switch to a tracker program so that we can count enrollments (which would be unique according to the ID mentioned above). However, we are not sure we need the complexity of a tracker program for any other reason than to produce this indicator.

@Markus do you think this request could be related to this JIRA request https://jira.dhis2.org/browse/DHIS2-5934) ?

1 Like

@Emma_Kassy - are you able to assist with this please?

This seems it would work - if you switch to a tracker program.

You could also try to use custom aggregation for the program indicator, to count distinct values.
Aggregation type: Custom
Expression: COUNT DISTINCT(#{your.data.element})

Custom aggregation types are not supported to view in the tracked entity instance dashboard however, only as calculated indicators in the aggregate apps.

Markus

1 Like

Thanks @Markus. We’ve tried the syntax for a custom aggregation for a program indicator that you shared and we were not able to get it to work. Does this only work on certain versions? We are on 2.31.4

1 Like

Thanks for letting us know. Custom aggregation types is supported in 2.31, but working with it there is a lot of freedom on the part of the kinds of expressions you can build - and there might be undocumented limitations. Could you send all the details on your program indicator?

1 Like

@Markus we tried a couple different syntax in the expression:

  • COUNT DISTINCT(#{dataElement})
  • count distinct(#{dataElement})
  • count(distinct(#{dataElement}))

For all, the UI said that the ‘expression is not valid’.

Otherwise, no filter was added. Aggregation type was set to custom and analytics type set to event.

1 Like

Thanks @Kris_Reinhardt,
I was expecting one of these to work:

Did you also try and run the program indicator in pivot tables? In such advanced cases it might be that the expression validation is a bit stricter than it should be - and it might be that the expression actually would work in pivot.

1 Like

@Markus yes - ran analytics (more than once :slight_smile:) but the PI is appearing as blank in pivot tables.