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

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

In the survey tab of your xlsform:

Data entry screen as seen in Enketo:

Reference xlsform:

Constraint Example.xlsx (10.7 KB)