# Hidden field calculation with questions nested in folder with display condition that doesn't trigger

**URL:** <https://forum.dimagi.com/t/hidden-field-calculation-with-questions-nested-in-folder-with-display-condition-that-doesnt-trigger/8197>\
**Category:** Users\
**Created:** [May 13, 2021, 7:44pm UTC](https://forum.dimagi.com/t/hidden-field-calculation-with-questions-nested-in-folder-with-display-condition-that-doesnt-trigger/8197 "2021-05-13T19:44:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![spope\_gnp](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/s/a183cd/32.png) [@spope\_gnp](https://forum.dimagi.com/u/spope_gnp)\
**Post date:** [May 13, 2021, 7:44pm UTC](https://forum.dimagi.com/t/hidden-field-calculation-with-questions-nested-in-folder-with-display-condition-that-doesnt-trigger/8197/1 "2021-05-13T19:44:36Z")

</div>

Hi CommCare fam,

Wondering if someone might help me figure out where I am going wrong with a hidden field calculation.

I am designing an app which will be used to digitize paper data. One of the questions in the form is "How many communities were visited?" with a maximum of 5.

I made a folder of questions to collect number of services conducted. Based on the numbers input, there is a hidden field calculation (ex: if 10 condoms were distributed, 10\*0.0083 to get the CYP).

In order to avoid repeat groups, I created 5 replicas of this initial set of questions/calculations, to display depending on the number of communities visited (1-5).

At the end of the app, I have a set of hidden field calculations in a separate group/folder that would sum the various indicators across these groups/folders. However, I am finding that these calculations "break" unless the user responds that they visited 5 communities, and subsequently they fill in all questions for all five folders/groups. If they only visit 2 communities and subsequently record data for 2, the within-folder/group calculations work, but the end-point/aggregating indicators at the end show blank.

Any ideas how I can work around this?

Thanks,  
Stephen

---

<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:** [May 13, 2021, 8:04pm UTC](https://forum.dimagi.com/t/hidden-field-calculation-with-questions-nested-in-folder-with-display-condition-that-doesnt-trigger/8197/2 "2021-05-13T20:04:13Z")

</div>

Hi Stephen,

How are you adding up the aggregate values?

If you are doing the straightforward thing (IE: #form/g1/q1 + #form/g2/q1 ...) you might try wrapping the individual questions with the [coalesce() function](https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions#CommCareFunctions-coalesce) which will give you an easy place to specify the 'default' answer for a blank value.

IE:

coalesce(#form/g1/q1, 0) + coalesce(#form/g2/q1, 0)...

---

<div class="post-metadata">

**Author:** ![spope\_gnp](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/s/a183cd/32.png) [@spope\_gnp](https://forum.dimagi.com/u/spope_gnp)\
**Post date:** [May 13, 2021, 8:49pm UTC](https://forum.dimagi.com/t/hidden-field-calculation-with-questions-nested-in-folder-with-display-condition-that-doesnt-trigger/8197/3 "2021-05-13T20:49:15Z")

</div>

Hi Clayton,

Thanks so much for the quick reply, and helpful solution! That did the trick, thank you so much!

Stephen
