These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How do I average multiple fields while excluding null and zero values?

EvieDee
Registered: Jul 2 2010
Posts: 12
Answered

My first experience on this site was F-A-N-T-A-S-T-I-C, so I am back hoping for the same outcome.
I am having a problem averaging fields that or either null or zeros.

I don't know if this can be done using Formcal, but here is the scenario…I have 20 fields, and I want to average all 20 fields if they contain non-zero or non-null values.

If they have null or zero values, then I want to ignore those fields. In other words, if 5 of the 20 fields have zeros or blanks, then I want to total the other 15 fields and divide by 15 to find the average (instead of all 20 fields.)

My Product Information:
LiveCycle Designer, Windows
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Hi,

for this purpose you can use a loop function in FormCalc.
Therefore all the numeric fields need the same naming.
The script than has to be put into the calculate:event of the field for the average.

  1. var nNonNullFields
  2. var nSum
  3. var nAverage
  4.  
  5. for i = 0 upto 19 do
  6. if (NumericField[i] > 0 and NumericField[i] ne null) then
  7. nNonNullFields = nNonNullFields + 1
  8. nSum = nSum + NumericField[i]
  9. nAverage = nSum / nNonNullFields
  10. endif
  11. $ = nAverage
  12. endfor

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

EvieDee
Registered: Jul 2 2010
Posts: 12
Radzmar,

Thanks again! This ia exactly what I needed...absolutely perfect!!!