# How to constraint a sum so that the inputs do not exceed the total entered previously?

I want the total sum to be matched with my question “Q”. meaning, if the figures they inputs in Q1 to Q5 already matched the amount in the question “Q”, they cannot write any figures.

Isavings calculation.xlsx (9.1 KB)

@Kal_Lam it should be like this.

You could do this as outlined in the post discussed previously:

Thank you so much @Kal_Lam . it was perfect!

1 Like

can we disable the items if the total of the other items reached the indicated amount from the previous question? meaning, if the first two items among the five reached the total amount already, they cannot encode in the last three items.

In this case, you could do this as outlined in the image shared below:

#### Reference xlsform:

Constraint Example.xlsx (10.7 KB)

Kal
Thank you for this help. I am not able to get it. Please help… My requirement is answer to second question should be less than or equal to first question. I am not authorised to upload a file. hence typing it here

type name label required contraint relevant calculation
start start
end end
decimal total Total land true
decimal kharif kharif true .>=0 and .<=\${total} \${total} > 0
calculate version ‘vgM5PJ3vQpqaoxkLuxZj6V’

Kal,
I am not getting the desired answer as mentioned above. Where am I doing mistake. Please help
Vali

@bhaktharvali, you missed to update your `relevant` column as shown in the image above. Update the same and your xlsform should also work.

1 Like

Kal
Thank you so much. It worked
Vali

1 Like

Hi Kal, i love this solution but my observation is that, when figures are below the total number stated it goes through as well.

Eg. Total = 20 , [ Boys = 5 , Girls = 1 ] - allowed [Boys = 0 Girls = 0] this is allowed

from the solution above this is allowed though total is 20. Is there a way to correct this?

Welcome to the community, @theo27! This final line added highlighted in yellow should help you achieve what you intend to:

#### Reference XLSForm:

Constraint Example.xlsx (10.9 KB)

Thank you for the help. But can the validation be done on Total instead of adding the note?

Hello @Kal_Lam ,

How do I apply this to my own challenge because its a bit similar but kind of different scenario.

If question A have five options and 3 option where selected, in Question B, the selected 3 options from Question A must be t0tal into 100 and if 4 options where selected the total in QB must be equals to 100 as well.

E.G
QA. What is your favorite fruit
Option 1 Mango
Option 2 Banana
Option 3 Apple
Option 4 Orange
Option 5 Berry
Note: if Option 2 Banana, Option 4 Orange and Option 5 Berry was selected.
I will now enter in number dividing the number among all selected but all must be equal to 100 if not I will not be able to access the next questions
QB. What is the total percentage you spend on favorite fruit, please all your entries must be equal 100 percent
Option 2 Banana, 25
Option 4 Orange 25
Option 5 Berry 50.
S the total is 100 percentages

@FEMMMY, could you elaborate/expalin this in more details?

a7HCEBRPXdBo5UG9wVmrSk (19).xlsx (59.7 KB)
Book1.xlsx (81.2 KB)

Hello @Kal_Lam al_lam

Kindly help this is urgent, I have attached the excel file and Questionnaire section was highlighted in red in file name Book1, I have highlighted in yellow column 131 to 148, I am trying to filter but its not displaying. I don’t know if the logic is wrong or not well highlighted

Quick respond will be appreciated

Thanks so much

@FEMMMY, it would be easy for the community to help you out if you share only the relevant section that has issues (or you wish to learn more about). Sharing the entire XLSForm should kill the time who wish to provide support to your issue. Thank you for your kind understanding!

Okay Thanks,

Actually the issues had being resolved.

Thanks

1 Like

Thank you for confirming @FEMMMY!