Hidden calculation to sum a value inside child cases

Hi guys

Has anyone ever tried having a form on a parent case sum all the values from its child cases in a specific property?

let’s say we’re collecting something like “How much money do you need for transportation?” in a property called “individual_transport_cost” and we were asking that question to a group of people who have cases that have the same parent. let’s say for the sake of argument that that parent case is the head of their household or community and that everyone’s case type is “respondent”.

suppose i had a followup form on the parent case, and inside that form, i wanted to have a calculation that showed me the sum of the transportation costs of his household members considering that they all have cases of their own, and i am currently updating the parent case.

i’m sure i’m just missing some syntax to call the casedb with a sum function or something like that. it’s much easier to just have a repeat and use a path to repeat in that function. but i’m more specifically interested in doing that when the objects i’m dealing with are either cases in casedb, or items in a lookup table.

what i’m really trying to do is to actually pull pieces of information from a case/lookup table that was selected in an advanced multiple select question that shows cases/lookup table entries.

any ideas will be appreciated

Mazz

Hi Mazz,

what i’m really trying to do is to actually pull pieces of information from a case/lookup table that was selected in an advanced multiple select question that shows cases/lookup table entries.

It sounds like what you are saying is “I have a list of cases I showed earlier in a form, a user selected N of them, and I want to sum up information from each selected case.”

That’s actually fairly straightforward, and you can use the selected() function when making a casedb query to do so, something like

sum(instance(‘casedb’)/casedb/case[selected(#form/previously_selected_cases, @case_id)]/value_to_sum_up)

Is that what you’re looking for?

-Clayton

I think so, i’m going to give it a shot

Mazz

Yeah, i think i can use this and some variations for what i need !

Thanks