# Get Difference of two numbers inside a repeat group

**URL:** <https://forum.dimagi.com/t/get-difference-of-two-numbers-inside-a-repeat-group/3549>\
**Category:** Users\
**Created:** [June 6, 2017, 3:52pm UTC](https://forum.dimagi.com/t/get-difference-of-two-numbers-inside-a-repeat-group/3549 "2017-06-06T15:52:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clayton\_Sims](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/clayton_sims/32/496_2.png) [@Clayton\_Sims](https://forum.dimagi.com/u/Clayton_Sims)\
**Post date:** [June 6, 2017, 3:52pm UTC](https://forum.dimagi.com/t/get-difference-of-two-numbers-inside-a-repeat-group/3549/1 "2017-06-06T15:52:42Z")

</div>

Hi Vipin,

If you would like this value to be computed for you, you can use a _Hidden  
Value_ to represent the difference (instead of an input question), and then  
setting the expression you have to take the difference as the  
_Calculate_ expression  
for that hidden value.

If you want to display the result to the user, you can create a _Label_ and  
drag the new hidden value into its display message to the user.

-Clayton

> **···**
>
> On Mon, Jun 5, 2017 at 5:18 AM, Vipin Gupta wrote:
> 
> > Hi,
> > 
> > In my form, I have repeat group and inside that repeat group, I have two  
> > numbers - planned and actual and in third number field I need a difference  
> > of those two numbers.
> > 
> > Enclosed is the screenshot of my form.
> > 
> > When I try to get difference it is giving me a warning and also it is not  
> > calculating the difference in the form.
> > 
> > Please advise.
> > 
> > Thanks,  
> > Vipin Gupta
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "commcare-users" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [commcare-users+unsubscribe@googlegroups.com](mailto:commcare-users+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![JayH](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/j/6a8cbe/32.png) [@JayH](https://forum.dimagi.com/u/JayH)\
**Post date:** [July 13, 2020, 2:25pm UTC](https://forum.dimagi.com/t/get-difference-of-two-numbers-inside-a-repeat-group/3549/2 "2020-07-13T14:25:01Z")

</div>

Hello @Clayton_Sims, @Mazz

How can i restrict a user from proceeding to another question if the addition of two questions using a hidden field does not equal 100?

---

<div class="post-metadata">

**Author:** ![Clayton\_Sims](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/clayton_sims/32/496_2.png) [@Clayton\_Sims](https://forum.dimagi.com/u/Clayton_Sims)\
**Post date:** [July 13, 2020, 2:46pm UTC](https://forum.dimagi.com/t/get-difference-of-two-numbers-inside-a-repeat-group/3549/3 "2020-07-13T14:46:14Z")

</div>

The most common pattern to follow for validation conditions which depend on the answers to multiple questions is to create a Label question with the Validation Condition false() whose display condition only makes it visible when the answers to the previous questions are invalid.

This allows you to pop up a message to explain the invalid input to the user, and block them from proceeding. Note: I believe the "block the user from proceeding" component of this solution currently doesn't work in Live Preview or Web Apps, but does work on the Android client, so you'll need to test that part on the phone directly.

---

<div class="post-metadata">

**Author:** ![JayH](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/j/6a8cbe/32.png) [@JayH](https://forum.dimagi.com/u/JayH)\
**Post date:** [July 13, 2020, 3:57pm UTC](https://forum.dimagi.com/t/get-difference-of-two-numbers-inside-a-repeat-group/3549/4 "2020-07-13T15:57:43Z")

</div>

Thanks but it still doesn't prevent the user from answering other questions. This is how i set it up

 ![image](https://dimagi.b-cdn.net/uploads/default/original/2X/d/d6ea750d00dc1ae2e2636eca838b33810fcee578.png)

---

<div class="post-metadata">

**Author:** ![JayH](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/j/6a8cbe/32.png) [@JayH](https://forum.dimagi.com/u/JayH)\
**Post date:** [July 13, 2020, 3:58pm UTC](https://forum.dimagi.com/t/get-difference-of-two-numbers-inside-a-repeat-group/3549/5 "2020-07-13T15:58:56Z")

</div>

I intentionally entered figures that didn't add up to 100 but it didn't prevent me from moving further into the survey, the only thing it did was not to display the label. How can i correct this please?

---

<div class="post-metadata">

**Author:** ![Clayton\_Sims](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/clayton_sims/32/496_2.png) [@Clayton\_Sims](https://forum.dimagi.com/u/Clayton_Sims)\
**Post date:** [July 13, 2020, 6:24pm UTC](https://forum.dimagi.com/t/get-difference-of-two-numbers-inside-a-repeat-group/3549/6 "2020-07-13T18:24:05Z")

</div>

Your check expression looks backwards to me, it should test for whether the condition is violated, rather than whether it passed.

---

<div class="post-metadata">

**Author:** ![JayH](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/j/6a8cbe/32.png) [@JayH](https://forum.dimagi.com/u/JayH)\
**Post date:** [July 16, 2020, 7:28am UTC](https://forum.dimagi.com/t/get-difference-of-two-numbers-inside-a-repeat-group/3549/7 "2020-07-16T07:28:28Z")

</div>

Hello @Clayton_Sims,

Still struggling with this please

 ![image](https://dimagi.b-cdn.net/uploads/default/original/2X/d/d420ecd2a44ea8600f595a2e16abaebaff865ad9.png)

This still permits the user to proceed even when the hidden calculation doesn't add up to 100.

---

<div class="post-metadata">

**Author:** ![Mazz](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/mazz/32/1004_2.png) [@Mazz](https://forum.dimagi.com/u/Mazz)\
**Post date:** [July 16, 2020, 8:21am UTC](https://forum.dimagi.com/t/get-difference-of-two-numbers-inside-a-repeat-group/3549/8 "2020-07-16T08:21:48Z")

</div>

try taking the single quotes out and just type the 100
