Solved

Acess 2007 sum multiple columns

Posted on 2010-09-13
9
475 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
  • 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 47

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 39

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 47

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

825 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