Solved

Acess 2007 sum multiple columns

Posted on 2010-09-13
9
474 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
 
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

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…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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.

867 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

18 Experts available now in Live!

Get 1:1 Help Now