Expand my Community achievements bar.

SOLVED

Calculating the mean (average) of user-entered numbers?

Avatar

Former Community Member

I'm trying to find a script that will calculate the average (mean) of user-entered data, the user may enter anywhere between 1 and 6 number values.  This is what I've tried in FormCalc:

var dcount=1;

if Row3.Cell6 !=null then (dcount=dcount+1);

if Row4.Cell6 !=null then (dcount=dcount+1);

if Row5.Cell6 !=null then (dcount=dcount+1);

if Row6.Cell6 !=null then (dcount=dcount+1);

if Row7.Cell6 !=null then (dcount=dcount+1);

(Row2.Cell6 + Row3.Cell6 + Row4.Cell6 + Row5.Cell6 + Row6.Cell6 + Row7.Cell6) / dcount

I've also tried

if HasValue (Row3.Cell6) then (dcount=dcount+1);

etc.

But I get syntax errors in both cases.  How can I fix the script so that this does what I need it to?

1 Accepted Solution

Avatar

Correct answer by
Level 8

Avg(Row3.Cell6,Row4.Cell6,Row5.Cell6,Row6.Cell6,Row7.Cell6)

Hint: If you name your rows the same (ex RowA) you can just put: Avg(RowA[*].Cell6) as your code

Kyle

View solution in original post

2 Replies

Avatar

Correct answer by
Level 8

Avg(Row3.Cell6,Row4.Cell6,Row5.Cell6,Row6.Cell6,Row7.Cell6)

Hint: If you name your rows the same (ex RowA) you can just put: Avg(RowA[*].Cell6) as your code

Kyle

Avatar

Former Community Member

Perfect yes, I figured this out on my own JUST as you posted your reply, thanks!