Horizontal Sum? Can I? Can I??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have numerous fields that need to summed in various ways.
Is there a function (or formula..) that will drive a query to sum a range
horizontally because my expressions are getting way to large....
Any suggestions?
 
This is a symptom of un-normalized table structures. Have you evaluated your
table structure according to good normalization practices?
 
The only way I know to do this is to use some vba to build a custom function to
sum all the values you pass to it.
UNTESTED AIR CODE FOLLOWS:

Public Function GetSum(ParamArray Values())
Dim dblSum As Double

  dblSum = 0

   For i = LBound(Values) To UBound(Values)
      If IsNumeric(Values(i)) Then           'Ignore Non-numeric values
         dblSum = dblSum + CDbl(Values(i))
      End If
   Next i
GetSum = dblSum

End Function

You can call it in a query by using it like any built in function.

Field: AddUp: GetSum([Table1].[Fieldc],[Table2].[FieldF],...)
 
Back
Top