Count indicators

Hello,
is there a way I can do to, which will allow indicators to count data elements that range from 40 -60?

1 Like

Dear @ahly,

Thank you for posting your question to the DHIS2 community!

Yes, I believe this is possible, with the d2:countIfCondition.

The documentation says:
Useful only for enrollment program indicators. Counts the number of data values that matches the given condition criteria for the given program stage and data element in the course of the enrollment. The argument data element is supplied with the #{programStage.dataElement} syntax. The condition is supplied as a expression in single quotes, for example ‘<10’ if only the values less than 10 should be counted.

Will let @dhis2-tracker add any additional information.

Best regards,
Karoline

Thank you for your response… but what I meant is not for program indicators… it’s for aggregate indicators?

Thank you for your response @ahly!

Tagging @Jim_Grace, is this possible with the ANTLR expressions for aggregate indicators?

Hi Ahly,

You can do this with predictors.

It is similar to Configuring predictors - Disease surveillance

The user manual on predictors is here: https://docs.dhis2.org/2.29/en/user/html/manage_predictor.html

Simple steps:

  1. Make a new data element for the predicted value to be stored.
  2. Make the predictor. The generator will be something like: if((#DE < 60 && #DE > 40),1,0) - This will count the number of times that data element is between 40 and 60.
  3. Set sequential and annual sample count to 1. This will mean that the generator only counts the previously period’s data. For example if you are looking at monthly data, and we are in May, then it will count the number of values between 40 and 60 in April.
  4. Next you will need to schedule the predictor to run in the scheduler application. In the sceduler application you’ll need to set the job type to predictor, select your predictor, and set the frequency. You can add a custom frequency as a cron expression if you like.
  5. Still in the scheduler application you’ll need to set a relative start and end. These are the number of days you want to reference for your predictor job. For example if you have monthly data and you set your relative start to -30 then it will run the predictor for all periods that occurred in the last 30 days. That is typically one or two months. The relative end is usually set to zero meaning the relative end is today. A relative end of 1 would mean tomorrow, for example.
  6. Run the predictor job.
  7. Run your analaytics tables. You’ll need to make sure your analytics tables are scheduled to run an hour or two after your predictor job just to make sure the predicted value is included in your analytics.
  8. Clear your cashe and make sure the data element tied to the predictor has a value.

Please let me know if you have any questions, and I hope this helps.

1 Like

Thanks am working on it

Just to expand on what @Scott said, the idea is that the predictor will essentially create a new data value for every input data value that you want to test, and store a 1 if the original data value is between 40 and 60, or a 0 if not. Then you can use an indicator to sum the predicted values, which tells you how many input values were between 40 and 60.

If you use a predictor generator expression that does not contain an aggregate function such as sum(), the input value is taken from the same period as the predicted value. So if your predictor generator function is if((#DE < 60 && #DE > 40),1,0) - this will store a value of 1 or 0 in the same period as the data element you are testing, and it won’t matter what the sequential and annual sample counts are set to.

But if your predictor generation has an aggregate function such as sum(), then any value(s) inside the aggregate functions are taken from one or more previous periods. So if your predictor generator function is if((sum(#DE) < 60 && sum(#DE) > 40),1,0) - this will sum the data element from previous periods and store a 1 or 0 in the predicted period. If your sequential count is 1 and the annual count is 0, this will examine a single data value in the previous period to see if it is between 40 and 60, and store a 1 or 0 in the period following the input data.

appreciate @Jim Grace