Your table structure should be something like
PeriodName
PeriodAmount
You would have a record for each Month. Your query would be straightforward
totals query.
With your current structure you need to use some VBA or some complex
calculated expressions in your query.
Paste the function below into a module and save the module with some other
name than fRowAverage. Perhaps Mod_Average
In your query add a calculated column that looks like the following.
Field: fRowAverage([Jan],[Feb],[Mar],[Apr],[May],...,{Dec]) as theAverage
'--------- Code follows --------------------------
Public Function fRowAverage(ParamArray Values())
'John Spencer UMBC CHPDM
'Last Update: April 5, 2000
'Calculates the arithmetic average (mean) of a group of values passed to it.
'Sample call: myAvg = GetMeanAverage("1","TEST","2", "3",4,5,6,0)
'returns 3 (21/7)
'Ignores values that cannot be treated as numbers.
Dim i As Integer, intElementCount As Integer, dblSum As Double
intElementCount = 0
dblSum = 0
For i = LBound(Values) To UBound(Values)
If IsNumeric(Values(i)) Then 'Ignore Non-numeric values
dblSum = dblSum + Values(i)
intElementCount = intElementCount + 1
End If
Next i
If intElementCount > 0 Then
fRowAverage = dblSum / intElementCount
'At least one number in the group of values
Else
fRowAverage = Null
'No number in the group of values
End If
End Function
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
MacNut2004 said:
Hello,
I have a dollar spread of a period of 12 months, but only want to average
the month amounts that have numbers in them. I.e. We are in march and
have
numbers in the january, february and march fields. I want these 3
averaged,
excluding April-December since they have null values. How can I do this in
a
query?
Thank you!
MN