Program indicator to count distinct values


I can’t figure out how to create a program indicator that will count only once the selected option set values of text data element in a repeatable program stage.

Data element: Test Result with these options: “positive, Negative, Not applicable”. What I want is that test result negative be counted only once even if selected multiple times in a repeatable program stage.

Any guidance would also be useful on how to achieve the same result in non reparable program stages.

Any help appreciated.


Hi @hernandezmachava

It sounds like what you want is an enrollment type program indicator with d2:countIfValue function.

For example, try enrollment type indicator, expression V{enrollment_count}, filter d2:countIfValue([ programStageUID ].[ TestResultDataElementUID ], ‘Negative’) >= 1
EDIT: proper syntax uses comma to separate stage and data element UIDs from the counted value.

This would count all enrollments where there is at least one Test Result (repeatable program stage) marked negative. The same approach would also work for non repeatable stages.

NB: By default, an enrollment type program indicator will use the enrollment date to determine the period each enrollment filters into. If some test results occur, say, 6 months after enrollment, and you want to count each enrollment with at least one negative test result in a given month, then you can use a custom program indicator period boundary, which would includes boundaries for event date as well as enrollment date.

More information about program indicator filters and period boundaries is available here.

Hi @brian,

I have tried to build the indicator in Sierra Leone Demo, but the filter says expression is not valid.
This is what the indicator looks like

Analytic type: Enrollment
Aggreagation type: Count
Expression: V{enrollment_count}


Sorry @hernandezmachava, I supplied the incorrect syntax! It should be

d2:countIfValue([ programStageUID ].[ TestResultDataElementUID ], ‘Negative’) >= 1
with a comma separating UID and the value.

It works on Play here

I have edited my reply above with proper syntax.

Hi @brian,

After separating the UID and the value with a comma, the filter gets validated but when I try to view the PI in the pivot table, I see no value. I have run the analytics.

I have registered two entities as test data for August. 1 has tested negative in three visits and the other has tested negative in the first two visits and positive in the 3r/last visit.

I ticked the display in form checkbox and the indicator shows 1 in the dashboard.

You have said that, “By default, an enrollment type program indicator will use the enrollment date to determine the period each enrollment filters into.” This has held my attention and I would to like to know what event-date means in relation to Program indicators building. Building program indicators has led to some confusion as I do not have much experience in this area.

Thanks again.

Hi @hernandezmachava it might be worth creating a new indicator with this same filter and trying again, or selecting different period dimensions. In later versions the pivot table cache does not always clear correctly for program indicators within the browser. But it may be working correctly since, as you say, the “display in form” indicator is showing correctly in the TEI dashboard.

The program indicators lounge had a few topics re: program indicator analytic period boundaries, which you may find interesting. 22 Sept - 16:00 - Tracker and Program Indicators - Experts Lounge Q&A