Академический Документы
Профессиональный Документы
Культура Документы
Introduction
My friend Bill tells me that he feels like a REBORN EXCEL USER since he has discovered the SUMPRODUCT formulas. Here are 136 of them to show you why. Data queried or downloaded from a data warehouse (Oracle, Sybase, SQL Server, etc.), a datamart (Access) or a major application (SAP, JDEdwards, PeopleSoft, etc.) look like the data in the "Data" sheet of this workbook. What you want is a report like the ones in the "Report" sheet of this workbook. Use the SUMPRODUCT formula. Your data can be on the same sheet as the SUMPRODUCT formula, in the same workbook or even in another workbook Often the number of lines (records) varies and the things are not on the same line as in the last download. With ordinary formulas, you cannot sub-total amounts or quantities based on one or more criteria. SUMPRODUCT formulas take care of all that. In the sheet "Formula" of this workbook, I explain to you how to build a SUMPRODUCT formula. Read carefully the note below to avoid problems.
Notes
The rows or columns used as references in a SUMPRODUCT formula must have the same number of cells, Ex : SUMPRODUCT((A1:A6="January")*(B1:B6)) NOT SUM ((A1:B6=January")*(A1:B7)). This is important to remember specially when you use named fields. Never include cells containing text in the ranges that you sum within SUMPRODUCT formulas you will end up with a "#VALUE" error message. So, no title cells. When you import data from certain old systems the cell with no data is not really empty. It might contain spaces and SUMPRODUCT formulas will result in a "#VALUE" error message. Remove these spaces by using the replace function where you enter a space in the to window and nothing in the "Replace by". Another situation tha can happen with data coming from an old system is that there can be spaces at the end of a string of character. For example, instead of having "Chicago" in a cell, you have "Chicago " because there are 15 spaces to enter the name of the city in the database. A SUMPRODUCT formula looking at this cell will not find "Chicago". You need to use the procedure mentionned in the previous paragraph to remode the spaces.
Your comments on this "Resource Workbook" would be appreciated: Click here: workbooks@excel-vba.com
(613) 749-4695
UCT
se, SQL Server, etc.), a datamart (Access) e the data in the "Data" sheet of this sheet of this workbook. Use the he SUMPRODUCT formula, in the same
n the same line as in the last download. based on one or more criteria.
mula must have the same number of cells, B6=January")*(A1:B7)). This is important
a is not really empty. It might contain or message. Remove these spaces by w and nothing in the "Replace by".
tem is that there can be spaces at the end n a cell, you have "Chicago " because A SUMPRODUCT formula looking at this ned in the previous paragraph to remode
There are other situations where SUMPRODUCT can be useful. For example imagine that you have a table of auto insurance rates with 5 columns for the sex, the age, the city, the type of car and the rate. You are looking for a rate, you do not really want to sum anything, you just want a single rate. The SUMPRODUCT formula will indeed sum colum "E" but as it will find a single rate based on the criterias it will give you your answer. Here what it would look like: =SUMPRODUCT((Data1!A2:A500="M")*(Data1!B2:B500=30)*(Data1!C2:C500="Chicago")*(Data1!D2:D500="Sedan")*(Data1! Copy/Paste SUMPRODUCT
This last section will probably sound very complex and confusing to begin with but I strongly recommend that you practice and become good at using the $ in addresses. It will save you a lot of time and keyboard work. Practice and, all of a sudden it will become clear. I apologize if my explanation sounds complex but it is this kind of thing that only becomes clear once you have practiced a few times. Like me you don't want to have to key in 100 formulas in a 10 X 10 table, you want to write a single formula in the top left cell of the table and copy/paste it all around. To do so, you need to master the art of absolute and relative addresses. You have to use the dollar signs to achieve the task because "B10", "$B10", "B$10" and "$B$10" do not react the same to copy/paste. First a MAJOR tip: you don't need to key in the dollar signs "$". You go to the formula bar (the window whre you enter text and numbers above the sheet), you click on an address and then you click on "F4" once ($B$10), twice (B$10), three times ($B10) and then a forth time to go back to (B10). I ALWAYS use "$" in ALL my formulas even the ones that I don't copy/paste to develop a reflex and not have to think how to do it each time I really need the THING. I ALWAYS use "$" in ALL my formulas because if I don't I will have to write hundreds of formulas instead of a single one. Once you are used to adding this thing "$" it gets very simple. If you copy/paste a formula with $B$10 right, left, up or down, "$B$10! will remain "$B$10" If you copy/paste a formula with B10 right or left the column "B" will change but the line "10" won't, if you copy it up or down, the "B" will remain but the "10" will change. If you copy/paste it diagonally, both "B" and "10" will change. If you copy/paste a formula with $B10 right or left the column "B" will NOT change and the line "10" won't change either, if you copy it up or down, the "B" will remain and the "10" will change. If you copy/paste it diagonally, "B" will remain but "10" will change. If you copy/paste a formula with B$10 right or left the column "B" will change but the line "10" won't, if you copy it up or down, the "B" will remain and so will the "10". If you copy/paste it diagonally, "B"will change but not the "10". Lets see the formula in cell B12 of the sheet "Report" of this workbook: =SUMPRODUCT((Data1!$B$2:$B$500=$A12)*(Data1!$C$2:$C$500=B$11)*(Data1!$E$2:$E$500)) All adresses for the database have two $ because wherever I copy/paste this formula, I want it to ALWAYS look at the same set of cells. This set up applies in 90% of the cases where your SUMPRODUCT formula looks at a database. Let's look at $A12 now. This refers to the title cell of the row so when I copy it laterally, I want it to still look at column "A" but Iwhen I copy it up/down I want the row number to change. As for the B$11 it refers to the title cell of the column so when I copy it laterally, I want the column address to change yet I want the row number to remain the same.en I copy it up/down I want the row number to change. In some cases when you look at a data set that carries monthly data in twelve different columns, the column that you sum can change so you will not put a $ in front of the column but you will keep the one in front of the row because wherever the formula is copy/pasted, you want to sum the same rows. In the formula above, you would use E$2:E$500 instead of $E$2:$E500$. Don't forget the notes in the Introduction about why a SUMPRODUCT results in an error. Enjoy and Good Luck
umn "C" is "Montreal" and the a formula (in blue above)) are
ed.
hen do not click on enter, just go to name of the sheet is not a single ere to tell Excel that both "Data"
you have a table of auto insurance king for a rate, you do not really sum colum "E" but as it will find a
)*(Data1!D2:D500="Sedan")*(Data1!E2:E500))
y recommend that you practice ork. Practice and, all of a sudden it hat only becomes clear once you a single formula in the top left cell
the window whre you enter text B$10), twice (B$10), three times
eflex and not have to think how to I don't I will have to write hundreds simple.
line "10" won't change either, if you ally, "B" will remain but "10" will
umns, the column that you sum of the row because wherever the use E$2:E$500 instead of
Month April April April April April April April April April April April April April April April April April April April April February February February February February February February February February February February February February February February February February February February February January January January January January January January January January January January January January January January
Product Bikes Bikes Bikes Bikes Skates Skates Skates Skates Skis Long Skis Long Skis Long Skis Long Skis Short Skis Short Skis Short Skis Short Snow Board Snow Board Snow Board Snow Board Bikes Bikes Bikes Bikes Skates Skates Skates Skates Skis Long Skis Long Skis Long Skis Long Skis Short Skis Short Skis Short Skis Short Snow Board Snow Board Snow Board Snow Board Bikes Bikes Bikes Bikes Skates Skates Skates Skates Skis Long Skis Long Skis Long Skis Long Skis Short Skis Short Skis Short
Store Quantity Amount Montreal 12 4500 Montreal 56 21000 San Francisco 854 320250 New York 25 9375 Montreal 56 5544 Toronto 854 84546 San Francisco 25 2475 New York 663 65637 Montreal 854 209230 Toronto 25 6125 San Francisco 663 162435 New York 21 5145 Montreal 21 4389 Toronto 4 836 San Francisco 522 109098 New York 136 28424 Montreal 4 1232 Toronto 522 160776 San Francisco 125 38500 New York 663 204204 Montreal 663 248625 San Francisco 21 7875 San Francisco 54 20250 New York 658 246750 Montreal 21 2079 Toronto 663 65637 San Francisco 21 2079 New York 136 13464 Montreal 522 127890 Toronto 125 30625 San Francisco 663 162435 New York 21 5145 Montreal 21 4389 Toronto 4 836 San Francisco 522 109098 New York 125 26125 Montreal 21 6468 Toronto 136 41888 San Francisco 21 6468 New York 4 1232 Montreal 75 28125 Toronto 12 4500 San Francisco 136 51000 New York 21 7875 Montreal 21 2079 New York 4 396 San Francisco 522 51678 New York 212 20988 Montreal 136 33320 Toronto 21 5145 San Francisco 4 980 New York 522 127890 Montreal 663 138567 Toronto 21 4389 San Francisco 136 28424
Add data down to line 500, move them around, sort them by city, by month, by product, by quantity, by amount and your reports still hold. Delete some rows, move them around and your reports still holds.
Modify the formulas in the report (change the 500 for 2000) and sum data up to line 1,000, or 2,000.
January January January January January March March March March March March March March March March March March March March March March March March March March
Skis Short Snow Board Snow Board Snow Board Snow Board Bikes Bikes Bikes Bikes Skates Skates Skates Skates Skis Long Skis Long Skis Long Skis Long Skis Short Skis Short Skis Short Skis Short Snow Board Snow Board Snow Board Snow Board
New York Montreal Toronto San Francisco New York Montreal Montreal San Francisco New York Montreal Toronto San Francisco New York Montreal Toronto San Francisco New York Montreal Toronto San Francisco San Francisco Montreal Toronto San Francisco New York
21 522 663 21 136 4 522 125 212 56 854 212 56 854 663 21 136 4 522 136 21 21 4 522 125
4389 160776 204204 6468 41888 1500 195750 46875 79500 5544 84546 20988 5544 209230 162435 5145 33320 836 109098 28424 4389 6468 1232 160776 38500
ta down to line 500, move them around, sort y city, by month, by product, by quantity, by and your reports still hold. Delete some rows, hem around and your reports still holds.
the formulas in the report (change the 500 for nd sum data up to line 1,000, or 2,000.
SUMPRODUCT Formulas
Modify the data in the "Data Sheet" and see the tables and charts change.
SUMMING Bikes Skates Skis Long Skis Short Snow Board Total COUNTING Bikes Skates Skis Long Skis Short Snow Board Total
Back to Introduction
In most of these tables, I have wr one SUMPRODUCT formula in th cell and copied it to the rest of the To do so, one must use wisely ab relative references ex.(B10, $B10 or $B$10 ??).
2,000 1,500
1,000 500
0
Bikes
0$
1,000,000 $
800,000 $
600,000 $
400,000 $
200,000 $ 0$
Back to Introduction
800,000 $ 600,000 $ 400,000 $ 200,000 $ 0$ Bikes Skates Skis Long Skis Short Snow Board
Montreal
Toronto
In most of these tables, I have written only one SUMPRODUCT formula in the top left cell and copied it to the rest of the table. To do so, one must use wisely absolute or relative references ex.(B10, $B10, B$10 or $B$10 ??).
Bikes
Skates
Snow Board
April
New York
Bikes
Skates
Skis Long
Skis Short
Snow Board
January February
March
Bikes
Skates
Snow Board
April
January
February March
Bikes
Skates
Snow Board
April
Montreal
Toronto New York San Francisco
January
February
March
April
January
February
March
April
Make Cadillac Cadillac Cadillac Cadillac Cadillac Cadillac Lincoln Lincoln Lincoln Lincoln Lincoln Lincoln
Year 2001 2002 2003 2001 2002 2003 2001 2002 2003 2001 2002 2003
Engine 8 cyl. 8 cyl. 8 cyl. 6 cyl. 6 cyl. 6 cyl. 8 cyl. 8 cyl. 8 cyl. 6 cyl. 6 cyl. 6 cyl.
Rate 0.04 0.05 0.06 0.07 0.08 0.09 0.14 0.15 0.16 0.17 0.18 0.19
Example 2 In this example your are also looking for a rate based on a salary. State New York New York New York Oregon Oregon Oregon From To Rate $0 $50,000 0.05 $50,001 $100,000 0.1 $100,001 $5,000,000 0.15 $0 $50,000 0.16 $50,001 $100,000 0.19 $100,001 $5,000,000 0.22