DHIS2 Program Rule Mathematical Functions

Hi everyone, I am building a tracker program on version 2.38.0 .
I am trying to raise a base number to a power (exponent) using program variables.
e.g.

#{ Variable - A } = 2
#{ Variable - B } = 5

#{ Variable - C } = ( #{ Variable - A } ) ^ ( #{ Variable - B } )

#{ Variable - C } = ANS

I have not been able to identify a function that can help me with this within the program rule configuration e.g.

NumPower( A, B)

which could be used in my case as:

NumPower( #{ Variable - A } , #{ Variable - B } )

Would someone be able to point me in the right direction or share any ideas that I can use to implement this calculation. Any assistance will be appreciated, thanks.

Hi, welcome to the community @Sika_Se :tada::tada::tada:

Would you like to share the use case and how this could be used? Preferably a real example. If condition which uses the exponent is = ANS then action?

I also need to ask if power ^ is supported in Program Rules - it is supported in Program Indicators.

thanks for your feedback @Gassim.

The program indicator functionality will be helpful for the reporting side.
However, in this case, I am trying to display calculated variables within a tracker program during data entry. These can be used as entry variables in other tracker programs within the same instance. E.g. a lab team calculate dosages for a certain combination of drugs in a lab tracker program and the team at the pharmacy can view the forms completed by the lab team and dispense drugs to patients based on the details in the lab forms while they complete forms in a pharmacy tracker which would be capturing different data elements.

1 Like

Any update on this?

Hey,

I received a response from @superskip and he said that instead of using ^ a double asterisk ** works (even though the parser claims it’s invalid)

Thanks!

1 Like

I would not recommend using this though. It works front-end but probably not on the server side. Also it is not officially supported, and if it ever will be, I think it’s more likely to be implemented using ^.

1 Like

thanks for the feedback people. I will try it out and let you know how it goes

1 Like