Does Program Indicator support nested if function?

I created a program indicator to classify children based on their anthropometry measurement but the problem is that when running the indicator no value is shown and I’m 100% correct about the structure of nested if so what could be the problem?

Edit expression section contains: V{event_count}

Edit filter section contains:

if( #{OOpMDvJpWOn.WdM083LLMX9} == 1,‘SAM’, if( #{OOpMDvJpWOn.WdM083LLMX9} != 1 && #{OOpMDvJpWOn.QIDnDvTcofn} >= 6 && #{OOpMDvJpWOn.QIDnDvTcofn} < 60 && (#{OOpMDvJpWOn.Nu1zSvDPVeD} < 11.5 || #{OOpMDvJpWOn.iZddxXt9eF9} < -3), ‘SAM’,if( #{OOpMDvJpWOn.WdM083LLMX9} != 1 && #{OOpMDvJpWOn.QIDnDvTcofn} >= 6 && #{OOpMDvJpWOn.QIDnDvTcofn} < 60 && (#{OOpMDvJpWOn.Nu1zSvDPVeD} >= 11.5 && #{OOpMDvJpWOn.Nu1zSvDPVeD} < 12.5) || (#{OOpMDvJpWOn.iZddxXt9eF9} > -3 && #{OOpMDvJpWOn.iZddxXt9eF9} < -2), ‘MAM’, ‘Normal’)))

so I hope someone guiding me in using nested if with program indicator.

Welcome to the community @ahmed_qaid! :tada:

Please make sure to run Analytics Tables export using the Data Administration app, and then clear the browser cache using the Browser Cache Cleaner app. After that please check again if you can find the values for the program indicator. To make sure it’s not a cache issue, please check again using the Guest Mode in your browser.

Which app are you using to view the values? If it still doesn’t work please reproduce the steps and before clicking on update to view the value, open the Network tab in the browser’s DevTools (F12). Click update to see the value, and then if there is any error in the Network tab or Console, please take a screenshot.

Thank you!

The edit filter section needs to be a boolean at the end so it knows whether to filter out or include each event. This looks like its formula will produce SAM, MAM, or Normal.

Feels like you’d be better suited to having Program Indicators for all three (SAM, MAM, Nomal) and then the filter would actually be a boolean, for example SAM:
#{OOpMDvJpWOn.WdM083LLMX9} == 1 || #{OOpMDvJpWOn.WdM083LLMX9} != 1 && #{OOpMDvJpWOn.QIDnDvTcofn} >= 6 && #{OOpMDvJpWOn.QIDnDvTcofn} < 60 && (#{OOpMDvJpWOn.Nu1zSvDPVeD} < 11.5 || #{OOpMDvJpWOn.iZddxXt9eF9} < -3

If you are confident with this expression, I suppose you could also do something like:
if( #{OOpMDvJpWOn.WdM083LLMX9} == 1,‘SAM’, if( #{OOpMDvJpWOn.WdM083LLMX9} != 1 && #{OOpMDvJpWOn.QIDnDvTcofn} >= 6 && #{OOpMDvJpWOn.QIDnDvTcofn} < 60 && (#{OOpMDvJpWOn.Nu1zSvDPVeD} < 11.5 || #{OOpMDvJpWOn.iZddxXt9eF9} < -3), ‘SAM’,if( #{OOpMDvJpWOn.WdM083LLMX9} != 1 && #{OOpMDvJpWOn.QIDnDvTcofn} >= 6 && #{OOpMDvJpWOn.QIDnDvTcofn} < 60 && (#{OOpMDvJpWOn.Nu1zSvDPVeD} >= 11.5 && #{OOpMDvJpWOn.Nu1zSvDPVeD} < 12.5) || (#{OOpMDvJpWOn.iZddxXt9eF9} > -3 && #{OOpMDvJpWOn.iZddxXt9eF9} < -2), ‘MAM’, ‘Normal’)))==‘SAM’
so that the boolean judges true or false on if it is a SAM event, and if so, allow the expression to happen.

1 Like

Thank you for your reply, I think the purpose of using nested if function is to avoid creating multiple program indicators and I want to include all three status (SAM, MAM and Normal) in one indicator

1 Like

Thank you for your prompt reply
I did your steps but it’s still showing nothing

1 Like

Please check if there are errors in the Network tab and/or Catalina.out log. Please share the log (without sensitive info).

++++

I managed to make it run by writing the formula in the Edit expression section:
if( #{OOpMDvJpWOn.WdM083LLMX9} == 1,1, if( #{OOpMDvJpWOn.WdM083LLMX9} != 1 && #{OOpMDvJpWOn.QIDnDvTcofn} >= 6 && #{OOpMDvJpWOn.QIDnDvTcofn} < 60 && (#{OOpMDvJpWOn.Nu1zSvDPVeD} < 11.5 || #{OOpMDvJpWOn.iZddxXt9eF9} < -3), 1,if( #{OOpMDvJpWOn.WdM083LLMX9} != 1 && #{OOpMDvJpWOn.QIDnDvTcofn} >= 6 && #{OOpMDvJpWOn.QIDnDvTcofn} < 60 && (#{OOpMDvJpWOn.Nu1zSvDPVeD} >= 11.5 && #{OOpMDvJpWOn.Nu1zSvDPVeD} < 12.5) || (#{OOpMDvJpWOn.iZddxXt9eF9} >= -3 && #{OOpMDvJpWOn.iZddxXt9eF9} < -2), 2, 3))) but the problem is that, Text is not allowed in (true-expr, false- expr) for if statement, for example in the above formula I wrote 1,2 and 3 instead of sam,mam and normal so how can I substitute 1,2 and 3 with sam,mam and normal. Is there a variable referring to the result of Edit expression section.

1 Like

Thank you for sharing the solution!

Could you clarify the question please? Thanks!

The result in the if function needs to be a number; however, one suggestion would be to create a program rule to show SAM, MAM, and normal depending on the result of the indicator so that if the result is 1 then (instead of using the indicator) the program rule will perform an action to show that it’s SAM. The action could be from displaying a message to assigning a value to a data element (depending on what’s needed for your use case). :sweat_smile:

Thank you!

Hello Gassim sorry for bothering you.
I’m beginner in DHIS2. how to assign a program indicator to a program rule, writing some steps will help me a lot.

1 Like

No, you are right! We can’t use program indicators in program rule expressions, so we need to figure out a solution :slight_smile: Thanks!

@ahmed_qaid

UPDATE:

Instead of using a program indicator, you could use several program rules:

PR1:
Expression: #{variable} == 1
Action: assign data element ‘SAM’

PR2:
Expression: (#{variable} != 1) && (#{variable} >= 6) && (#{variable} < 60) && (#{variable} < 11.5 || #{variable} < -3)
Action: assign data element ‘SAM’

PR3:
Expression: ((#{variable} != 1) && (#{variable} >= 6) && (#{variable} < 60) && (#{variable} >= 11.5) && (#{variable} < 12.5)) || (#{variable} >= -3) && (#{variable} < -2)
Action: assign data element ‘MAM’

PR4:
Expression: (#{data-element} != ‘SAM’) && (#{data-element} != ‘MAM’)
Action: assign data element ‘Normal’


Hope this one solves it! Please test and feel free to post back if there are other issues. :+1:

Thanks!

1 Like