Finding the Average with sum and count , and repeat groups ( with excluding 0)


(Shawn) #1

I need to average 11 questions and exclude 2 questions if they = 0 from the total average. i.e. from the numerator and denominator in div to perform average.

Will the above execute, so that if domain 3 or if domain 4 =0 then they are excluded from the calculation? I attempted to achieve this by creating a repeat group to repeat the count () of the sum hidden value.

Finally, I attempted to use my repeat group (that should count the number of items to sum) as the denominator for the calculation.

Will this accurately, provide me the average of 11 items excluding those that are zeros?
Bonus points: Where can I check the result of my calculations? Other than running it in web apps i have no clue if it is calculating correctly, or what the final scores are.

Thanks to those willing to help out.


(Clayton Sims) #2

Hi Shawn,

Four quick points of feedback

  1. I don’t think ‘default’ you added looks right. You’re adding numbers together, so adding ‘default’ will break the calculation

  2. Your repeat count does seem correct, that should work as long as the sum is a number in all of the repeat instances

  3. Putting a Display Condition directly on the Repeat node is a bit sketchy. I generally put the display condition on a group inside the repeat, so it’s clear that a repeat exists, but without any relevant quesitons

  4. You can use the Web Apps data preview to see what your calculations are resulting in live in the form. You can also test individual xpath expressions, but be aware that you can’t really test the outcome of a calculation with the “Evaluate XPath” expression if that expression is “inside” of a repeat.

-Clayton


(Shawn) #3

Thanks Clayton for the response. You were correct about a repeat count. I have this now, however, it still doesn’t update for the by the number (counts)

divisible, any suggestions.


(Shawn) #4

In addition, I was able to correctly calculation the hidden values through the web app, however, the repeat group does this:

What could I do to alleviate this issue?


(Clayton Sims) #5

Hi Shawn,

I’m confused about what you are trying to compute with the ‘default’ tags you’re still adding together values with a non-numeric default, which will result in a non-numeric output

-Clayton


(Shawn) #6

Hi Clayton,

I have the default page because of the statement syntax for cond(). I basically want to say that, add 9+ question3 if it is >0, if it is not greater than 0, than I need a "null or "default value. This is because if an answer choice is 0, i need that 0 excluded from the total about to divide by.

Provides the correct calculations when there are no 0 values however, when there are 0 values, the calculations do not run . More screenshots if that helps


(Clayton Sims) #7

What do you expect for the calculation to return when the ‘null’ case is met, and why is ‘0’ not the best ‘null’ choice?

If you add 3 + ‘default’ in CommCare, the result will be an invalid answer (NaN), so I don’t think ‘default’ is the right input there


(Shawn) #8

I expect that “null” will be the output, and that it will be excluded from the demominator ( last screenshot beginning with 9+cond().

Similar to, Sum(1,2, 3), if 3 <0 then exclude 0 value from calculation: effectively, averaging
-> only two numbers. I believe ‘0’ is not the best choice because it will still be an integer that will be calculated to obtain the the denominator score and then the average.

However, I am willing to try anything to get this issue resolved.
Best- Shawn


(Clayton Sims) #9

Hi Shawn,

I believe that removing non-answered questions from the denominator by only adding 1 if the question was answered, and 0 if it was not addresses the concern you are describing.

You won’t be able to get a numeric output from the equations if the math involves non-numeric values.


(Shawn) #10

Thanks Clayton, I will try that right now. fingers-crossed


(Shawn) #11

Clayton, you are the best, I was able to calculate a sum of all my fields based of your suggestion… Thanks!!!