Solved

Acess 2007 sum multiple columns

Posted on 2010-09-13
9
473 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
Comment Utility
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
Comment Utility
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
Comment Utility
For the sum(jab+feb+dec), it will give me three months total or 12?
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 21

Expert Comment

by:chapmanjw
Comment Utility
It will add the values of the fields, not count the fields.
0
 
LVL 39

Expert Comment

by:als315
Comment Utility
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
Comment Utility
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
Comment Utility
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)
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now