Using SUMPRODUCT to matchi dentifiers in 2 columns and 1 row

Rainmanne

Board Regular
Joined
Mar 10, 2016
Messages
134
Office Version
  1. 2019
Platform
  1. Windows
I've got data organised in the following way: 2 first columns are identifiers and the rest of the columns are values by year (a year per column). So I need to summarise it in a different table based on 2 identifiers an by year. So each value in the summary table should match the combination of two identifiers in the first two columns and organaised by year. There could be multiple rows matching the combination of the identifiers thus using the SUMPRODUCT formula:

Excel Formula:
=SUMPRODUCT((--(FS!$B$4:$B$150=CF!$A5)),(--(FS!$C$4:$C$150=CF!$B5)),FS!G$4:G$150)

But ideally I would like to capture the last array with the data based on the year rather hardwire it into the formula as it is now. I tried to use INDEX/MATCH in the last part but it does not work.

Also, SUMPRODUCT seems to be quite heavy on resources so I wonder if it's possible to replace it with something less resource hungry?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Some small sample data and expected results would probably help clarify your requirement.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Sorry, it has taken some time to set it up. Please see two sheets below:

test for forum.xlsx
ABCDEFGHIJK
1A ID1 ID2 ID3 IDRoundingThousandsThousandsThousandsThousandsThousandsThousands
20000Statement Date12/31/200912/31/201012/31/201112/31/201212/31/201312/31/2014
30000Periods121212121212
40500TOTAL
51050555PR1a2,979,1034,580,6826,708,4847,028,8058,904,70411,797,517
61100555PR1b000000
71150577PR2a000000
820001577PR2b134,771128,95941,78034,8869310
9120051015PR33,832,2724,037,2364,635,9046,669,6838,418,5749,268,139
10130051120Disc182,489192,249456,584446,188325,620194,104
11123051380PR5000000
12124051316PR6115,165272,735505,1201,164,202724,518418,548
13125051280PR4a548,292822,167670,009578,573788,704950,439
142001351280PR4b416,674615,492998,8231,441,1711,718,2912,137,179
15167052565PR8a409,753316,422440,122709,920853,4891,079,029
16168052565PR8b000000
17140051525PR712,5215,2197,0437,5938,95817,285
18145051625PR72484,043356,113452,235702,019724,378688,650
19150051725PR73a1,5509,24623,73254,24968,62647,987
202000451725PR73b102,73588,1919,48336,2939,98345,862
21155052035PR7438,31979,30247,70492,963136,456107,396
22160052035PR74144,15438,107114,842301,660403,798287,497
23995035221135Exchange Rate0.574300.600170.533110.489360.423350.37627
Base



Cell Formulas
RangeFormula
F1:J1F1=RIGHT(OFFSET(Base!E2,,IF(COUNTA(Base!$2:$2)=8,COUNTA(Base!$2:$2)-7,IF(COUNTA(Base!$2:$2)=9,COUNTA(Base!$2:$2)-8,COUNTA(Base!$2:$2)-9))),4)
F3:J3F3=SUM(F4:F5,F8,F9:F15,F17:F17)
F4:J7,F9:J15,F17:J17F4=SUMPRODUCT((--(Base!$B$2:$B$23=$A4)),(--(Base!$C$2:$C$23=$B4)),(--(Base!$D$2:$D$23=$C4)),Base!F$2:F$23)*F$18
F8:J8F8=F6-F7
F16:J16F16=SUM(F12:F15)
F18:J18F18=IF(INDEX(Base!$1:$1048576,MATCH($E18,Base!$E:$E,0),MATCH(TRUE,INDEX(RIGHT(Base!$2:$2,4)=F$1,0),0))=0,1,INDEX(Base!$1:$1048576,MATCH($E18,Base!$E:$E,0),MATCH(TRUE,INDEX(RIGHT(Base!$2:$2,4)=F$1,0),0)))


Hopefully it works.
 
Upvote 0
Basically I need to match the year column and I cannot figure out how.
 
Upvote 0
I may have more questions to follow, but to try to get some understanding, can you please answer these?
  1. Can you confirm whether the dates in row 2 of 'Base' are actual dates (numbers) or text values?
  2. Can you explain in words what the OFFSET formula in row 1 of 'Table' is supposed to do?
  3. Is 'Table' showing the results that you want? That is what I asked for but I'm not sure that is what you have given since all those cells contain formulas, not manually entered expected results.
 
Upvote 0
I may have more questions to follow, but to try to get some understanding, can you please answer these?
  1. Can you confirm whether the dates in row 2 of 'Base' are actual dates (numbers) or text values?
  2. Can you explain in words what the OFFSET formula in row 1 of 'Table' is supposed to do?
  3. Is 'Table' showing the results that you want? That is what I asked for but I'm not sure that is what you have given since all those cells contain formulas, not manually entered expected results.
Thanks a lot for looking into it! Please see below:

1. The dates are not actual dates but numbers. If you look into Format Cells... they are formatted as numbers.
2. It takes the year from the table for each columns. Basically the year is the four last digits of the date in row 2 in Base sheet.
3. No, the results are wrong. I need to take the data from the last five years. So the years in Table are correct and the exchange rates in row 18 are correct as well. But the other data are taken from a wrong year. The current formula only works if there are 5 years or less in the Base. It doesn't if the number of years is higher. Probably there's a more elegant way to do it.

Thanks a lot again!
 
Upvote 0
. The dates are not actual dates but numbers. If you look into Format Cells... they are formatted as numbers.
That is still somewhat unclear to me. In a blank cell in sheet 'Base' put this formula and tell us the result =ISNUMBER(H2)

It takes the year from the table for each columns. Basically the year is the four last digits of the date in row 2 in Base sheet.
That is not clear to me either. The last four digits in F2 of 'Base' are 2009 but F1 in 'Table' says 2010

3. No, the results are wrong.
So to better understand, I would like to see the correct results with a clear explanation for a couple of them how you came up with those results manually.
 
Upvote 0
That is still somewhat unclear to me. In a blank cell in sheet 'Base' put this formula and tell us the result =ISNUMBER(H2)
It returns FALSE for H2
That is not clear to me either. The last four digits in F2 of 'Base' are 2009 but F1 in 'Table' says 2010
Yes, because the Row1 in Table is correct. The formula takes the last 5 years regardless how many years are in Base. The issue I have I cannot do the same for the data, so I need to match the year in Row1 with the data under the same year in Base. At the moment the data in the formula in the Table columns is hardwired to the columns in the base. It works fine for the cases where there 5 years or less of data. But if it's more than 5 years of data, the columns are mismatched. The exchange rate row in Table is also correct as it uses a different formula.
So to better understand, I would like to see the correct results with a clear explanation for a couple of them how you came up with those results manually.
Please see below the expected results. I have hardwired 2010 column in the table to G column in Base and filled it right.

Cell Formulas
RangeFormula
F1:J1F1=RIGHT(OFFSET(Base!E2,,IF(COUNTA(Base!$2:$2)=8,COUNTA(Base!$2:$2)-7,IF(COUNTA(Base!$2:$2)=9,COUNTA(Base!$2:$2)-8,COUNTA(Base!$2:$2)-9))),4)
F3:J3F3=SUM(F4:F5,F8,F9:F15,F17:F17)
F4:J7,F9:J15,F17:J17F4=SUMPRODUCT((--(Base!$B$2:$B$23=$A4)),(--(Base!$C$2:$C$23=$B4)),(--(Base!$D$2:$D$23=$C4)),Base!G$2:G$23)*F$18
F8:J8F8=F6-F7
F16:J16F16=SUM(F12:F15)
F18:J18F18=IF(INDEX(Base!$1:$1048576,MATCH($E18,Base!$E:$E,0),MATCH(TRUE,INDEX(RIGHT(Base!$2:$2,4)=F$1,0),0))=0,1,INDEX(Base!$1:$1048576,MATCH($E18,Base!$E:$E,0),MATCH(TRUE,INDEX(RIGHT(Base!$2:$2,4)=F$1,0),0)))
 
Upvote 0
OK, thanks. I think that I sort of understand now.

It returns FALSE for H2
OK, so those dates must be text values then as far as I can see. Note that cell formatting does not alter the underlying cell value so a cell can be formatted as number but contain text.

You may still have to adjust some ranges to suit your possible data but I would try to avoid the huge ones (eg Base!$1:$1048576). Just make them big enough to be sure to cover any expected data.
I'm also not too sure about how you want to handle it if there are less than 5 years in 'Base'.
Anyway, this may give you something to build on. The formulas that I have adjusted are green and I have not altered the white cell formulas.

Cell Formulas
RangeFormula
F1F1=RIGHT(LOOKUP("z",Base!$F2:$Z2),4)-4
G1:J1G1=F1+1
F3:J3F3=SUM(F4:F5,F8,F9:F15,F17:F17)
F4:J7,F9:J15,F17:J17F4=SUMPRODUCT((--(Base!$B$5:$B$40=$A4)),(--(Base!$C$5:$C$40=$B4)),(--(Base!$D$5:$D$40=$C4)),INDEX(Base!$F$5:$Z$40,0,MATCH("*/"&F$1,Base!$F$2:$Z$2,0)))*F$18
F8:J8F8=F6-F7
F16:J16F16=SUM(F12:F15)
F18:J18F18=IF(INDEX(Base!$F5:$Z40,MATCH($E18,Base!$E5:$E40,0),MATCH("*"&Table!F1,Base!$F2:$Z2,0))=0,1,INDEX(Base!$F5:$Z40,MATCH($E18,Base!$E5:$E40,0),MATCH("*"&Table!F1,Base!$F2:$Z2,0)))
 
Upvote 0
Solution
OK, thanks. I think that I sort of understand now.


OK, so those dates must be text values then as far as I can see. Note that cell formatting does not alter the underlying cell value so a cell can be formatted as number but contain text.

You may still have to adjust some ranges to suit your possible data but I would try to avoid the huge ones (eg Base!$1:$1048576). Just make them big enough to be sure to cover any expected data.
I'm also not too sure about how you want to handle it if there are less than 5 years in 'Base'.
Anyway, this may give you something to build on. The formulas that I have adjusted are green and I have not altered the white cell formulas.

Cell Formulas
RangeFormula
F1F1=RIGHT(LOOKUP("z",Base!$F2:$Z2),4)-4
G1:J1G1=F1+1
F3:J3F3=SUM(F4:F5,F8,F9:F15,F17:F17)
F4:J7,F9:J15,F17:J17F4=SUMPRODUCT((--(Base!$B$5:$B$40=$A4)),(--(Base!$C$5:$C$40=$B4)),(--(Base!$D$5:$D$40=$C4)),INDEX(Base!$F$5:$Z$40,0,MATCH("*/"&F$1,Base!$F$2:$Z$2,0)))*F$18
F8:J8F8=F6-F7
F16:J16F16=SUM(F12:F15)
F18:J18F18=IF(INDEX(Base!$F5:$Z40,MATCH($E18,Base!$E5:$E40,0),MATCH("*"&Table!F1,Base!$F2:$Z2,0))=0,1,INDEX(Base!$F5:$Z40,MATCH($E18,Base!$E5:$E40,0),MATCH("*"&Table!F1,Base!$F2:$Z2,0)))
Hi, it's worked perfectly! Thanks so much for your help!
 
Upvote 0

Forum statistics

Threads
1,224,737
Messages
6,180,653
Members
452,992
Latest member
TokugawaIesuma

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top