Greatest function for indicators

Hello,

When using an indicator to formulate an expression for the highest/greatest/max value in a list of values, the greatest() function for indicators, in a dataset, is not working.

Issue replicated in DHIS2 Play:

  1. Navigate to Maintenance

  2. Navigate to the Indicator tab > Select ‘Indicator’ from left side menu

  3. Click on plus button to create a new Indicator

  4. Enter a Test Indicator Name

  5. Enter a Test Indicator Short Name

  6. Select the Indicator type: Factor 1

  7. Click on the ‘Edit Numerator’ button

  8. Enter the Numerator description “Returns the greatest/highest/max value”

  9. Enter the greatest function expression:
    “greatest(#{BDuY694ZAFa}, #{ixDKJGrGtFg}, #{M3anTdbJ7iJ}, #{dHrtL2a4EcD}, #{RR538iV9G1X})”
    i.e. greatest(EXP Cars Expense, EXP Drugs Expense, EXP Salary Expense, EXP Security Expense, EXP Sheets Expense)

  10. Confirm validity of expression

  11. Click on Done

  12. Click on ‘Edit Denominator’ button

  13. Enter the Denominator description “1”

  14. Enter the greatest function expression: 1

  15. Click on Done

  16. Click on Save

  17. Assign Indicator to Dataset

  18. Clear Cache

  19. Assign Indicator to correct Section

  20. Clear Cache

  21. Navigate to Data Entry Beta app to enter relevant values and test if greatest value appears for newly formulated indicator
    Indicator

For Tracker/Event Programs the work around is to use program rules, i.e. if there are 3 values (A,B,C) to choose from, the solution is to create 3 separate program rules with the following structure:

Name: Assign X if greatest
Condition: #{A} > #{B} && #{A} > #{C}
Actions: Assign #{A} to greatest field

For datasets using the aggregate model, the work around is a little more difficult because a series of nested ‘if’ statements have to be used instead.

For max 2 values: if(a > b, a, b)
For max 3 values:
if(a > b, if(a > c, a, c), if(b > c, b, c) )
For max 4 values:
if(a > b, if(a > c, if(a > d, a, d), if(c > d, c, d) ), if(b > c, if(b > d, b, d), if(c > d, c, d) ) ) )

This is quite time consuming. Imagine there are 10+ values in a dataset that the greatest value needs to be confirmed for. It would be good if there was a fix for indicator functions such as greatest() going forward.

With testing I’ve experienced this issue with the greatest() function using the following versions:
→ Data Entry Beta app: v100.3.10 and DHIS2: v2.40.3
→ Data Entry Beta app: v100.5.2 and DHIS2: v2.41.0.1

I have submitted a ticket here: [DHIS2-17805] - Jira

Thanks!

3 Likes

Hi @TaraRichards

Thank you for the detailed post. I have tried to replicate the issue while making several changes:

  1. tried to change the data type to number instead of integer or zero value type - didn’t work
  2. Although it was time consuming, I ran the tables analytics export for the aggregate data - didn’t work
  3. tried to use the least() expression in the same way as the greatest() - didn’t work
  4. I cleared the cache every step of the way… and tried both legacy and beta data entry apps - didn’t work
  5. also tried this greatest(1,2,3,5,6)… and this if(greatest(#{}…etc)>5,1,0)

I was wondering if there’s a specific configuration step that could make it work but I guess it’s probably not working. Thanks for the ticket, will ask for further support.

Thanks!

2 Likes