Counting from dropdown list

Need your assistance
Created a program rule to calculate the total hunger score from three (3) different DE (dropdown list). Namely: B3, B4 and B5
Each DE has three dropdown options, (Never, Sometimes and Often).

Where Never =0, Sometimes=1, and Often=2

  1. Created DE called Total hunger score
  2. Created 9 Program variables (B3_score0, B3_Score1, B3_Score2, same apply for B4 and B5
  3. Created 9 Program rule for each program variable
    Condition: d2:hasValue(‘Screen_B3_score0’) && #{Screen_B3_score0} == 'Never ’
    Assign “0” to it’s program variable. This process was repeated to all 8 variables with respective scores
  4. Created another PR that sums up all the 9 Program Rule Variables
    Condition:d2:hasValue(#{B3}) && d2:hasValue(#{B4}) && d2:hasValue(#{B5})
    Expression: #{B3_score0} +#{B3_score1} +#{B3_score2} + #{B4_score0} +#{B4_score1} +#{B4_score2} +#{B5_score0} +#{B5_score1} +#{B5_score2}
    4(a). Assigned to DE in step 1

The result is simply a blank field

Is this happening in Android or in web?

Hi Jaime,
It’s Web V2.35

The logic seems good to me. Could you make a test and change the condition on point 4 to true (nothing else). To see if the value is calculated?

Hi Jaime, I changed to true.

Its concatenating instead of Adding

Can you check if this post helps you? It describes more or less what you wanted to achieve and I included a metadata.json file in case you want to import it.


Thanks Jaime

Will look into this. I will keep you posted

And I just realized that you might be experiencing what this other user reported: Addition of calculated Program Rule Variables concatenates values instead of adding :frowning:

Ow! i see what is happening. Thanks a lot for sharing this. What’s your advice in this regard.

Probably follow the recommendation from the @dhis2-tracker and fill a bug in JIRA. Unfortunately I didn’t have the time to test and report it myself. But considering that you already have the program I think you could even export a JSON of your program and attach it to the issue in JIRA.