D2:round in Program Rules - round is not defined (fixed)

Hi All,
I’m having a problem using d2:round in the calculation of an assign value action in a Program Rule. I’m just trying to calculate BMI by rounding the outcome of Weight over Height squared. See error below.

I can get around this by first assigning Weight/Height squared to a PRV, then having a second Program Rule assign d2:round(PRV) to the BMI data element, but it seems weird that d2:round cannot handle this in one program rule as I had originally defined it.

1 Like

Hi @kstankevitz,

I tested this on different versions too and it doesn’t seem to work for me either. I’m asking @tracker-program rules to help out.

If it turns out that this is a bug would you like to create a bug issue in jira.dhis2.org? Thanks!

Happy to report if we determine this is a bug. Thanks.

Hey there @kstankevitz,
We just fixed a bug that might have been causing this;

The problem was that it was not possible to have nested expressions passed as an argument to the d2:functions. In short, the parenthesis inside the calculation makes the evaluation fail.

Until the bug fix is rolled out, a workaround can be to make the calculation #/(#*#) in a separate rule, and assign this to a calculated variable. If you create a new program rule variable called for example #{bmi}, you can assign the variable #{bmi} by the calculation above. Remember to set a rule of priority 1, so the helper variable #{bmi} gets assigned before your current rule.
With the current program rule variable #{bmi} set, you can change your current rule to d2:round(#{bmi}) - and this should work.