Well, the biggest problem is that your data is not normalized. Your table
really should look more like
RowNumberField (Some way to identify what was a row in your original table)
ValueName (p1, p2, etc)
FieldValue (value you currently store in p1, p2, etc.)
If you are trying to generate an average of those eight values for the row.
You will have to use something along the lines of
= (Nz(P1,0) + Nz(P2,0) ...+Nz(P3,0)) / ( IIF(P1 is null,0,1) + IIF(P2 is
Null,0,1) ...IIF(P8 is Null,0,1))
You could normalize the data using a union all query and then use that for
your calculations. You would need another field in the original table to
uniquely identify each row. An autonumber field would work fine.
Sample UNION ALL query
SELECT AutonumberField, P1 as FieldValue, "P1" as ValueName
FROM YourTable
UNION ALL
SELECT AutonumberField, P2, "P2"
FROM YourTable
UNION ALL
....
SELECT AutonumberField, P8, "P8"
FROM YourTable
Now using that saved query as a basis, you could do
SELECT AutonumberField
, Avg(FieldValue) as AverageValue
, Count(FieldValue) as FieldsWithValue
, Min(FieldValue) as MinValue
, Max(FieldValue) as MaxValue
FROM [TheSavedQuery]
GROUP BY AutoNumberField
If you wanted the average for P1 to P8 in the entire set
SELECT ValueName
, Avg(FieldValue) as AverageValue
FROM [TheSavedQuery]
GROUP BY ValueName
zachnjoe said:
I have a simple database form used to collect numerical values(p1, p2
....up
to p8). I want to perform some calculations on the values that are input
but
all the boxes are not always used so I want to ignore unfilled boxes. As
a
simple example: I would like to calculate the average of the input numbers
and if only 3 out of the 8 boxes are filled, I get an error. My control
is:
=avg([p1]+[p2]+[p3]+[p4]+[p5]+[p6]+[p7]+[p8]). I want blanks to be
ignored.