Math operations in Program Indicator using d2:condition

Hello everyone,

We´re trying to create a PI that calculate a score using Yes/No DEs. Since a Null value can be in the DE (if no response), then we use the following expression:

(d2:condition(’#{XHb8oH6AjDT.y37QCBqibki}==1’,1,0)*2)/(d2:condition(‘d2:hasValue(‘XHb8oH6AjDT.y37QCBqibki’)==true’,1,0)*2)

Interesting thing is the math operation seems not to be working, and the indicator triggers a “False” value. When we try only with the numerator or denominator separately, the expression works perfectly!

Please your kind support and ideas will be much appreciated

DHIS2 version 2.30, in case need it.

Thanks!

1 Like

Hi Ana Maria,

Is it possible that this is because your formula can result in a denominator of zero? (Dividing by zero is mathematically problematic, and the result is therefore ‘undefined’ - although I think DHIS2 displays this as ‘NaN’ rather than ‘false’.) This would also explain why each part of the formula works fine on its own, and the error only occurs if you divide one by the other…

What result are you aiming to achieve with this formula? And how are you using this program indicator (eg are you displaying it in Tracker Capture, or using it in a pivot table?)

Cheers, Sam.

1 Like

Hi Sam!
Glad to have news from you!
Thanks much for responding my note. This is related to the HNQIS scoring, a composite and overall one. After several tests, we decided to drop out this function and we´re using a variable that counts the No Null values in a Yes/No DE. and it worked!

We thought that using the d2 condition function we could avoid the nulls since those not count in the denominator, but it didn´t work.

Now, we´ve managed with that “value_count” variable :slight_smile:

Many thanks anyway Sam, for your suggestions!

Best

AM

1 Like