Sum a range of a nested index match

Grengis

New Member
Joined
Jul 14, 2023
Messages
1
Office Version
  1. 365
  2. 2019
  3. 2013
Platform
  1. Windows
Hi
I have data laid out as follows

Record datePaid dateIncome 1Income 2
Income 3
Investment 1
30/06/202212/07/20220510
Subtotal0510
Investment 2
31/12/202112/01/202251020
30/06/202212/07/2022546
Subtotal101426

I'm trying to create a formula in another worksheet which will have the following output
Investment name (manually entered)Income 1 (formulas)Income 2 + 3 (formulas)
Investment 1015
Investment 21040

I need a formula which will:
  1. Look up the investment name in the first table
  2. Find the "Subtotal" line related to this line. Please note, this isn't an excel subtotal line rather, the data is simple called "subtotal"
  3. From the subtotal line, return a particular income figure (so Income 1 in table 2 above) or sum of multiple columns (income 2 and 3 in table 2 above).
I believe it's necessary to use an Index/Match formula combination to do this. Some googling of this has allowed me to simple return a single value (e.g. Income 1 figure) with the following formula:
Excel Formula:
=INDEX(INDEX(C1:C7,MATCH(G1,A1:A7,0)):C7,MATCH("Subtotal",INDEX(A1:A7,MATCH(G1,A1:A7,0)):A7,0))
but I don't fully understand how this is working which also means I can't figure out sum part.

I'd appreciate some advice on:
  1. How to achieve the Income 2+3 formulas in table two
  2. Some explanation as to how the Income 1 formula index/match works.
If there's a better way to achieve the result rather than index/match, I'm all ears. Thank you.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
try this:
I added a couple extra rows for Inv 1 as part of my testing:
This requires SUBTOTAL row immediately after the last investment row of each section.
And I am using a blank row after the last SUBTOTAL.


Book1
ABCDE
1Record datePaid dateIncome 1Income 2Income 3
2Investment 1
32022-06-302022-07-120510
42022-09-302022-10-15123
52022-11-302022-12-10456
6Subtotal51219
7Investment 2
82021-12-312022-01-1251020
92022-06-302022-07-12646
10Subtotal111426
11
12Investment 1531
13Investment 21140
Grengis
Cell Formulas
RangeFormula
C6:E6C6=SUBTOTAL(9,C3:C5)
C10:E10C10=SUBTOTAL(9,C8:C9)
B12B12=SUM(INDEX($A$1:$E$11,MATCH($A12,$A$1:$A$11,0)+1,3):INDEX($A$1:$E$11,MATCH($A13,$A$1:$A$11,0)-2,3))
C12C12=SUM(INDEX($A$1:$E$11,MATCH($A12,$A$1:$A$11,0)+1,4):INDEX($A$1:$E$11,MATCH($A13,$A$1:$A$11,0)-2,5))
B13B13=SUM(INDEX($A$1:$E$11,MATCH($A13,$A$1:$A$11,0)+1,3):INDEX($A$1:$E$11,IF($A14="",COUNTA($A$1:$A$11)-1,MATCH($A14,$A$1:$A$11,0)-2),3))
C13C13=SUM(INDEX($A$1:$E$11,MATCH($A13,$A$1:$A$11,0)+1,4):INDEX($A$1:$E$11,IF($A14="",COUNTA(A1:A11)-1,MATCH($A14,$A$1:$A$11,0)-2),5))
 
Last edited:
Upvote 0
try this:
I added a couple extra rows for Inv 1 as part of my testing:
This requires SUBTOTAL row immediately after the last investment row of each section.
And I am using a blank row after the last SUBTOTAL.


Book1
ABCDE
1Record datePaid dateIncome 1Income 2Income 3
2Investment 1
32022-06-302022-07-120510
42022-09-302022-10-15123
52022-11-302022-12-10456
6Subtotal51219
7Investment 2
82021-12-312022-01-1251020
92022-06-302022-07-12646
10Subtotal111426
11
12Investment 1531
13Investment 21140
Grengis
Cell Formulas
RangeFormula
C6:E6C6=SUBTOTAL(9,C3:C5)
C10:E10C10=SUBTOTAL(9,C8:C9)
B12B12=SUM(INDEX($A$1:$E$11,MATCH($A12,$A$1:$A$11,0)+1,3):INDEX($A$1:$E$11,MATCH($A13,$A$1:$A$11,0)-2,3))
C12C12=SUM(INDEX($A$1:$E$11,MATCH($A12,$A$1:$A$11,0)+1,4):INDEX($A$1:$E$11,MATCH($A13,$A$1:$A$11,0)-2,5))
B13B13=SUM(INDEX($A$1:$E$11,MATCH($A13,$A$1:$A$11,0)+1,3):INDEX($A$1:$E$11,IF($A14="",COUNTA($A$1:$A$11)-1,MATCH($A14,$A$1:$A$11,0)-2),3))
C13C13=SUM(INDEX($A$1:$E$11,MATCH($A13,$A$1:$A$11,0)+1,4):INDEX($A$1:$E$11,IF($A14="",COUNTA(A1:A11)-1,MATCH($A14,$A$1:$A$11,0)-2),5))


To see how each formula works, use the Evaluate formula section and cycle through each step. You will see that by using the colon ( : ) in the formula that the index function creates a RANGE and not values (not sure if that is the exact definition of the reference functionality of the INDEX function, but it works for me.)
 
Upvote 0
Welcome to the MrExcel board!

With MS365 you could try these

23 07 15.xlsm
ABCDE
1Record datePaid dateIncome 1Income 2Income 3
2Investment 1
330/06/202212/07/20220510
430/09/202215/10/2022123
530/11/202210/12/2022456
6Subtotal51219
7Investment 2
831/12/202112/01/202251020
930/06/202212/07/2022646
10Subtotal111426
11
12Inc 1Inc 2 + 3
13Investment 1531
14Investment 21140
Income
Cell Formulas
RangeFormula
B13:B14B13=INDEX(FILTER(C$2:C$10,(A$2:A$10="Subtotal")*(ROW(C$2:C$10)>MATCH(A13,A:A,0)),0),1)
C13:C14C13=SUM(INDEX(FILTER(D$2:E$10,(A$2:A$10="Subtotal")*(ROW(D$2:E$10)>MATCH(A13,A:A,0)),0),1,0))
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

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