Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Acess 2007 sum multiple columns

Posted on 2010-09-13
Medium Priority
481 Views
Hi,

I am looking for a function in Access that can sum a range of columns. In my table, I have 12 months of sales data in crosstab format. In other words, the table look like this:

Part#    Jan    Feb......Dec
1234     12     32...... 34

What I want to achieve is sum on running bases. For example, for the month Mar., sum the sales for Jan and Feb, while for the month of July, sum the sales from Jan thru Jun. There are business reasons why I need to do this way. Question is how to make the Sum function work in Access. I know in Excel you can simply put a range, Sum(A1:A12). That does not seem to work in Access.

Appreciate any ideas!
0
Question by:nnrsc
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 2
• 2
• +2

Author Comment

ID: 33664478
I know I can put in like [Jan]+[Feb]+..., but apparently this is too manual when it becomes 12 months.
0

LVL 21

Expert Comment

ID: 33664526
You could edit the SQL query of the view and do something like this:

SELECT partnumber, SUM(jan + feb + dec) AS total FROM tablename
0

Author Comment

ID: 33664535
For the sum(jab+feb+dec), it will give me three months total or 12?
0

LVL 48

Accepted Solution

Dale Fye earned 2000 total points
ID: 33664569
Access does not have a built in function that will sum across columns like Excel will do for you.  The other thing you need to be aware of is that just summing the columns, without using the NZ( ) function to convert NULL values to 0 will result in a NULL, so you really need to do:

NZ([Jan], 0) + NZ([Feb], 0) + ... +NZ([Dec], 0)

I would write this out once to all 12 months, then I would copy it into the other columns, deleting from the right as you go.

0

LVL 21

Expert Comment

ID: 33664572
It will add the values of the fields, not count the fields.
0

LVL 40

Expert Comment

ID: 33664640
I you table will have "normal" data structure:
Part# Month(Date)  Value
1234          1              25
1234          2              13
1234          5              17

here is example:
http://www.datapigtechnologies.com/flashfiles/runningsum.html
and many other examples:
http://www.datapigtechnologies.com/AccessMain.htm
0

Author Closing Comment

ID: 33665358
Good to know there is no shortcut to do this in Access. And thanks for the extra help on pssible null values.

I am aware of the data normalization situation. But the data come from another source which I have no control. So I have to take them in the format available.
0

LVL 93

Expert Comment

ID: 33665547
Glad to see you got an answer!For the future, you might want to consider the approach taken in my article http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_1775-Computing-row-wise-aggregations-in-Access.htmlIt involves adding a UDF :)Patrick
0

LVL 48

Expert Comment

ID: 33665917
Patrick,

I like the function.  I've got a set of similar, single purpose functions, but like the way you have grouped this together into a single package.  I also like the way you have incorporated the ability to pass an array as one of the "values" in the parameter array.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
###### Suggested Courses
Course of the Month9 days, 5 hours left to enroll