# Calculating percentages

Hello Guys,
i am working on a questionnaire for supervision and it has a lot of calculations, i have been able to make the sum ups which are coming automatically but my problem is how do i design it in a way that it allows for auto-calculation of a percentage?for example you put var1, var2 has to be 5 % of var1.

Hi @Nondo,

ODK does not support auto-calculation. The calculations that you want have to be computed manually. For instance, in your example, you have to compute the 5% using the [calculate](https://docs.opendatakit.org/form-question-types/?highlight=calculate#calculate.

Also, look at https://docs.opendatakit.org/form-logic/#expressions

Thanks for that @dicksonsamwel let me go through and give it a try....

Hello @Nondo ,

Depending on what you want to achieve there are possible solutions.

A) If you want to automatically calculate var2 = x% of var1 you can do as @dicksonsamwel suggested.

• Assuming the value entered by the user is called var1, you can define a new variable var2 with type calculate and calculation field: \${var1} *x div 100 (e.g. for 5% it would be \${var1} *5 div 100
• You can round the result to the number of decimals you want using the operator round(field, digits)

B) If the users is supposed to enter both var1 and var2 and you want the form to validate whether the user entered the correct value for var2 you can do as follows:

• Calculate var2 as per step A)
• add another numeric variable var2_user that the user can enter manually
• If you want to force the value entered to be equal to the theoretical one, you can add a constraint .=\${var2} This might not be the best approach in my opinion.
• If you want to check the discrepancy in the background you can add another variable eg. var2_diff with the desired calculation
For example abs(\${var2} div \${var2_user} -1) calculates the absolute value of the difference between the theoretical value and the value entered by the user in % points. This can be particularly useful if you allow an error (possibly due to to rounding of the calculation) based on a percentage.

I hope this helps.

Cheers,
Andrea

1 Like