Solved

Acess 2007 sum multiple columns

Posted on 2010-09-13
9
478 Views
Last Modified: 2012-05-10
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
Comment
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
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 

Author Comment

by:nnrsc
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

by:chapmanjw
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

by:nnrsc
ID: 33664535
For the sum(jab+feb+dec), it will give me three months total or 12?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 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

by:chapmanjw
ID: 33664572
It will add the values of the fields, not count the fields.
0
 
LVL 40

Expert Comment

by:als315
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

by:nnrsc
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 92

Expert Comment

by:Patrick Matthews
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

by:Dale Fye (Access MVP)
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question