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:
-
Navigate to Maintenance
-
Navigate to the Indicator tab > Select ‘Indicator’ from left side menu
-
Click on plus button to create a new Indicator
-
Enter a Test Indicator Name
-
Enter a Test Indicator Short Name
-
Select the Indicator type: Factor 1
-
Click on the ‘Edit Numerator’ button
-
Enter the Numerator description “Returns the greatest/highest/max value”
-
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)
-
Confirm validity of expression
-
Click on Done
-
Click on ‘Edit Denominator’ button
-
Enter the Denominator description “1”
-
Enter the greatest function expression: 1
-
Click on Done
-
Click on Save
-
Assign Indicator to Dataset
-
Clear Cache
-
Assign Indicator to correct Section
-
Clear Cache
-
Navigate to Data Entry Beta app to enter relevant values and test if greatest value appears for newly formulated 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!