Rounding number in expression of numerator of an Indicator


I need to be able to round (actually ceil) a division into the expression of the numerator of an Indicator, it seems impossible to do in DHIS2?

The expression is simply : Ceil(DE1/DE2) but d2:ceil() available in program indicator does not work (expression is dubbed as invalid), without any rounding function or a integer division is not possible to have a workaround. And if I would want to “bypass” this I am stuck by not being able to implement an indicator using the results of two others indicator.

Am I missing something or a workaround?

Thanks :slight_smile:

Hi @ekhalil

d2:ceil works in program rules so there’s a way to make a program rule that would convert the value and assign it to a variable and then using it in the program indicator.

Alternatively, you could use a math calculation which will return the ceil:
(#{DE1} + #{DE2} - 1)/(#{DE2})

I already tried the approximation and it does not work due to the fact than the division is not an integer division in DHIS2 :
if DE1 = 756 and DE2 = 56 then CEIL(756/56) = 14 and (756 + 56 - 1) / 56 = 14.482142857142858 is the division operator is not an integer division.

Do I have a misunderstanding about the nature of the division operator available in Indicator expression engine ?

Okay! In this case, I have an idea. Here’s a suggestion using a program rule:

  1. Create a data element of type Positive or Zero Integer and add it to the program

  2. Create a program rule, true expression, and assign value to the new data element. Expression d2:ceil(DE1/DE2) is valid in program rule engine:

  3. Create a program indicator, you will be able to find the data element to add to the expression



Thanks for the idea but unfortunately, I am working with Datasets and Indicator not Program and Program Indicator (my life would have been easier :D). I don’t think there any way to round/floor/ceil a number into the expression engine of an Indicator due to the lack of functions and/or lack of integer division.

Apologies, I thought you’re using program indicator since it was mentioned in your first post. I’d need to look around and see if there’s a way in the aggregate.

It might be possible to create a feature request but maybe there’s a way of doing it, so let’s check first.


1 Like

Hi @ekhalil

Are you using a custom form in your dataset? If yes, then you can use a javascript to populate the result. Here’s an example:

<div style="display:grid;grid-template-columns: 0.4fr auto;">
<label for="DE1">DE1:</label>
<input id="DE1" type="text" placeholder="Enter text" onblur="check()">
<label for="DE2">DE2:</label>
<input id="DE2" type="text" placeholder="Enter text" onblur="check()">
<label for="result">Result:</label>
<input id="result" type="text" placeholder="" readonly="readonly">

function check() {
const val1 = document.querySelector('#DE1').value;
const val2 = document.querySelector('#DE2').value;
if((val1 != '')&&(val2 != '')){ceil(val1,val2)}

function ceil(v1,v2) {
document.querySelector('#result').value = Math.ceil(v1/v2);

Test the code above:

1 Like