Dynamic Subtotal of column after each row entry has been multiplied by two-way lookup

PrettyGood_Not Great

Board Regular
Joined
Nov 24, 2023
Messages
102
Office Version
  1. 365
Platform
  1. Windows
Hi, I have a challenge to produce a column total above the header row, where the total is the sum product of the entire row, after each entry has been multiplied against the rate table. Currently showing in row A of the data table is the double XLOOKUP to find the rate.

Thanks to @Fluff for the solution in column H where this operation is being performed for the rows. The challenge here is to have the same results for the column totals, BUT it needs to produce a subtotal when filtering on the Charge Codes (column I). Anyone know a 365 solution to this?

Note it will also need to handle error cases due to empty lookups.

PGNG.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXY
1Subtotal-->192.5198.3192.5192.5192.5192.5192.5192.5192.5192.5192.5192.5198.3198.3198.3
2RateCode20232024202520262027SUM ResultCharge CodeSkill/RateJan-24Feb-25Mar-24Apr-24May-24Jun-24Jul-24Aug-24Sep-24Oct-24Nov-24Dec-24Jan-25Feb-25Mar-25
3R1186.9192.5198.3204.2210.3270335.5A101A1R1108120150114114138757590717575687547
4R2131.9135.9139.9144.1148.5187151.2A102B1R281120150114114138757590717575687547
5R3106109.2112.4115.8119.373782A103C1R3414556434352454554434545414528
6R482.184.587.189.792.490305.8A104D1R468759471718675759071756868750
7R547.348.750.151.653.246930.4A105E1R561688464647868688164686161680
Sheet1
Cell Formulas
RangeFormula
K1:Y1K1=XLOOKUP(RIGHT($J3,2),$A$3:$A$7,XLOOKUP(YEAR(K$2),$B$2:$F$2,$B$3:$F$7))
H3:H7H3=SUM(MAP($K$2:$Y$2,K3:Y3,LAMBDA(a,b,b*XLOOKUP(RIGHT($J3,2),$A$3:$A$7,XLOOKUP(YEAR(a),$B$2:$F$2,$B$3:$F$7)))))
 

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.
Assuming that the rate code in column A always matches the rate code embedded in column J,
this would work:

Cell K1:
=SUMPRODUCT(--(RIGHT($J3:$J7,2)=$A3:$A7),K$3:K$7,INDEX($B$3:$F$7,0,MATCH(YEAR(K$2),$B$2:$F$2,0)))

You can drag this across the top row.

Best,
JL
 
Upvote 0
This resembles an earlier request that evolved over time to accommodate filtering and missing data. To account for those things, and to take advantage of Excel 365's spilling array feature, I would tackle it as shown below. Note that I've shifted the two tables so that a filter can be applied to the column I Charge Codes (which will hide some of the righthand table rows) while still allowing the lefthand table to remain visible. I've also inserted the suggestion from @JumpingCrab, but that doesn't spill and it doesn't account for filtering, as hidden Charge Codes are still considered, as demonstrated in the lower snippet.
MrExcel_20240505.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXY
1
2RateCode20232024202520262027
3R1186.9192.5198.3204.2210.3
4R2131.9135.9139.9144.1148.5
5R3106109.2112.4115.8119.3
6R482.184.587.189.792.4
7R547.348.750.151.653.2
8
944991.855581.36740951249.551249.562063.239193.139193.147002.537128.339193.138260.736584.940362.319042.6
10Subtotal-->44991.855581.36740951249.551249.562063.239193.139193.147002.537128.339193.138260.736584.940362.319042.6
11
12SUM ResultCharge CodeSkill/RateJan-24Feb-25Mar-24Apr-24May-24Jun-24Jul-24Aug-24Sep-24Oct-24Nov-24Dec-24Jan-25Feb-25Mar-25
13270335.5A101A1R1108120150114114138757590717575687547
14187151.2A102B1R281120150114114138757590717575687547
1573782A103C1R3414556434352454554434545414528
1690305.8A104D1R468759471718675759071756868750
1746930.4A105E1R561688464647868688164686161680
PGNG_Sheet1
Cell Formulas
RangeFormula
K9:Y9L9=SUMPRODUCT(--(RIGHT($J13:$J17,2)=$A3:$A7),L$13:L$17,INDEX($B$3:$F$7,0,MATCH(YEAR(L$12),$B$2:$F$2,0)))
K10:Y10K10=LET( rary, IFERROR(INDEX(B3:F8,XMATCH(RIGHT(J13:J17,2),$A$3:$A$8,0),XMATCH(YEAR(K12:Y12),B2:F2,0)),""), vis, MAP(J13:J17,LAMBDA(r,--(SUBTOTAL(103,r)=1))), res,BYCOL(SEQUENCE(,COLUMNS(K12:Y12)),LAMBDA(x, IF(AND(CHOOSECOLS(rary,x)=""),"",SUMPRODUCT(CHOOSECOLS(K13:Y17,x),CHOOSECOLS(rary,x),vis)))), res)
H13:H17H13=IFERROR(BYROW(J13:Y17,LAMBDA(br,SUM(MAP($J$12:$Y$12,br,LAMBDA(a,b,IF(AND(ISNUMBER(a),ISNUMBER(b)),b*XLOOKUP(RIGHT(INDEX(br,,1),2),$A$3:$A$8,XLOOKUP(YEAR(a),$B$2:$F$2,$B$3:$F$8)),0)))))),"")
Dynamic array formulas.

MrExcel_20240505.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXY
1
2RateCode20232024202520262027
3R1186.9192.5198.3204.2210.3
4R2131.9135.9139.9144.1148.5
5R3106109.2112.4115.8119.3
6R482.184.587.189.792.4
7R547.348.750.151.653.2
8
944991.855581.36740951249.551249.562063.239193.139193.147002.537128.339193.138260.736584.940362.319042.6
10Subtotal-->31797.9405844926037437.637437.645319.224630246302955623316.4246302463022997.62536515895.4
11
12SUM ResultCharge CodeSkill/RateJan-24Feb-25Mar-24Apr-24May-24Jun-24Jul-24Aug-24Sep-24Oct-24Nov-24Dec-24Jan-25Feb-25Mar-25
13270335.5A101A1R1108120150114114138757590717575687547
14187151.2A102B1R281120150114114138757590717575687547
18
PGNG_Sheet1
Cell Formulas
RangeFormula
K9:Y9L9=SUMPRODUCT(--(RIGHT($J13:$J17,2)=$A3:$A7),L$13:L$17,INDEX($B$3:$F$7,0,MATCH(YEAR(L$12),$B$2:$F$2,0)))
K10:Y10K10=LET( rary, IFERROR(INDEX(B3:F8,XMATCH(RIGHT(J13:J17,2),$A$3:$A$8,0),XMATCH(YEAR(K12:Y12),B2:F2,0)),""), vis, MAP(J13:J17,LAMBDA(r,--(SUBTOTAL(103,r)=1))), res,BYCOL(SEQUENCE(,COLUMNS(K12:Y12)),LAMBDA(x, IF(AND(CHOOSECOLS(rary,x)=""),"",SUMPRODUCT(CHOOSECOLS(K13:Y17,x),CHOOSECOLS(rary,x),vis)))), res)
H13:H17H13=IFERROR(BYROW(J13:Y17,LAMBDA(br,SUM(MAP($J$12:$Y$12,br,LAMBDA(a,b,IF(AND(ISNUMBER(a),ISNUMBER(b)),b*XLOOKUP(RIGHT(INDEX(br,,1),2),$A$3:$A$8,XLOOKUP(YEAR(a),$B$2:$F$2,$B$3:$F$8)),0)))))),"")
Dynamic array formulas.
 
Upvote 1
Solution
This resembles an earlier request that evolved over time to accommodate filtering and missing data. To account for those things, and to take advantage of Excel 365's spilling array feature, I would tackle it as shown below. Note that I've shifted the two tables so that a filter can be applied to the column I Charge Codes (which will hide some of the righthand table rows) while still allowing the lefthand table to remain visible. I've also inserted the suggestion from @JumpingCrab, but that doesn't spill and it doesn't account for filtering, as hidden Charge Codes are still considered, as demonstrated in the lower snippet.
MrExcel_20240505.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXY
1
2RateCode20232024202520262027
3R1186.9192.5198.3204.2210.3
4R2131.9135.9139.9144.1148.5
5R3106109.2112.4115.8119.3
6R482.184.587.189.792.4
7R547.348.750.151.653.2
8
944991.855581.36740951249.551249.562063.239193.139193.147002.537128.339193.138260.736584.940362.319042.6
10Subtotal-->44991.855581.36740951249.551249.562063.239193.139193.147002.537128.339193.138260.736584.940362.319042.6
11
12SUM ResultCharge CodeSkill/RateJan-24Feb-25Mar-24Apr-24May-24Jun-24Jul-24Aug-24Sep-24Oct-24Nov-24Dec-24Jan-25Feb-25Mar-25
13270335.5A101A1R1108120150114114138757590717575687547
14187151.2A102B1R281120150114114138757590717575687547
1573782A103C1R3414556434352454554434545414528
1690305.8A104D1R468759471718675759071756868750
1746930.4A105E1R561688464647868688164686161680
PGNG_Sheet1
Cell Formulas
RangeFormula
K9:Y9L9=SUMPRODUCT(--(RIGHT($J13:$J17,2)=$A3:$A7),L$13:L$17,INDEX($B$3:$F$7,0,MATCH(YEAR(L$12),$B$2:$F$2,0)))
K10:Y10K10=LET( rary, IFERROR(INDEX(B3:F8,XMATCH(RIGHT(J13:J17,2),$A$3:$A$8,0),XMATCH(YEAR(K12:Y12),B2:F2,0)),""), vis, MAP(J13:J17,LAMBDA(r,--(SUBTOTAL(103,r)=1))), res,BYCOL(SEQUENCE(,COLUMNS(K12:Y12)),LAMBDA(x, IF(AND(CHOOSECOLS(rary,x)=""),"",SUMPRODUCT(CHOOSECOLS(K13:Y17,x),CHOOSECOLS(rary,x),vis)))), res)
H13:H17H13=IFERROR(BYROW(J13:Y17,LAMBDA(br,SUM(MAP($J$12:$Y$12,br,LAMBDA(a,b,IF(AND(ISNUMBER(a),ISNUMBER(b)),b*XLOOKUP(RIGHT(INDEX(br,,1),2),$A$3:$A$8,XLOOKUP(YEAR(a),$B$2:$F$2,$B$3:$F$8)),0)))))),"")
Dynamic array formulas.

MrExcel_20240505.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXY
1
2RateCode20232024202520262027
3R1186.9192.5198.3204.2210.3
4R2131.9135.9139.9144.1148.5
5R3106109.2112.4115.8119.3
6R482.184.587.189.792.4
7R547.348.750.151.653.2
8
944991.855581.36740951249.551249.562063.239193.139193.147002.537128.339193.138260.736584.940362.319042.6
10Subtotal-->31797.9405844926037437.637437.645319.224630246302955623316.4246302463022997.62536515895.4
11
12SUM ResultCharge CodeSkill/RateJan-24Feb-25Mar-24Apr-24May-24Jun-24Jul-24Aug-24Sep-24Oct-24Nov-24Dec-24Jan-25Feb-25Mar-25
13270335.5A101A1R1108120150114114138757590717575687547
14187151.2A102B1R281120150114114138757590717575687547
18
PGNG_Sheet1
Cell Formulas
RangeFormula
K9:Y9L9=SUMPRODUCT(--(RIGHT($J13:$J17,2)=$A3:$A7),L$13:L$17,INDEX($B$3:$F$7,0,MATCH(YEAR(L$12),$B$2:$F$2,0)))
K10:Y10K10=LET( rary, IFERROR(INDEX(B3:F8,XMATCH(RIGHT(J13:J17,2),$A$3:$A$8,0),XMATCH(YEAR(K12:Y12),B2:F2,0)),""), vis, MAP(J13:J17,LAMBDA(r,--(SUBTOTAL(103,r)=1))), res,BYCOL(SEQUENCE(,COLUMNS(K12:Y12)),LAMBDA(x, IF(AND(CHOOSECOLS(rary,x)=""),"",SUMPRODUCT(CHOOSECOLS(K13:Y17,x),CHOOSECOLS(rary,x),vis)))), res)
H13:H17H13=IFERROR(BYROW(J13:Y17,LAMBDA(br,SUM(MAP($J$12:$Y$12,br,LAMBDA(a,b,IF(AND(ISNUMBER(a),ISNUMBER(b)),b*XLOOKUP(RIGHT(INDEX(br,,1),2),$A$3:$A$8,XLOOKUP(YEAR(a),$B$2:$F$2,$B$3:$F$8)),0)))))),"")
Dynamic array formulas.
@KRice, wow. Amazing! the K10 formula is works perfectly, catches the error handling as well. Thanks so much!
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,128
Members
453,021
Latest member
Justyna P

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