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
95
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?

book1.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXY
1Subtotal-->192.5192.5192.5192.5192.5192.5192.5192.5192.5192.5192.5192.5198.3198.3198.3
2RateCode20232024202520262027SUM ResultCharge CodeSkill/RateJan-24Feb-24Mar-24Apr-24May-24Jun-24Jul-24Aug-24Sep-24Oct-24Nov-24Dec-24Jan-25Feb-25Mar-25
3R1186.9192.5198.3204.2210.3269685.2A101A1R1108120150114114138757590717575687547
4R2131.9135.9139.9144.1148.5186573.3A102B1R281120150114114138757590717575687547
5R3106.0109.2112.4115.8119.373516.2A103C1R3414556434352454554434545414528
6R482.184.587.189.792.490737.4A104D1R468759471718675759071757568750
7R547.348.750.151.653.247005.4A105E1R561688464647868688164686861680
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)))))
 
Last edited by a moderator:
Where are the blanks (or perhaps text)?...Are they in the main table?...columns K:Y in the example I posted?

And to which header row are you referring? Is it the main table...K2:Y2 in the example I posted? Are those sometimes blank?

Does the Skill/Rate column ever have blanks?
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Where are the blanks (or perhaps text)?...Are they in the main table?...columns K:Y in the example I posted?

And to which header row are you referring? Is it the main table...K2:Y2 in the example I posted? Are those sometimes blank?

Does the Skill/Rate column ever have blanks?
Yes to all. In the working file the J:Y range is templated for a large set of data, and associated structure, which will almost always have empty cells. For example, K2:Y2 is formatted for 5 years worth of months, but usually won't be populated for the full duration. J:J also will almost never be fully populated. and the data range K3:Y8 will be populated randomly.
 
Upvote 0
I added error traps in both formulas to handle cases where blanks might appear, or text in the main table (see orange cells).
MrExcel_20231231.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXY
13072427945139162785239279256052560530726241742560525605235752641512244
2
3SUM ResultSkill/Rate4529245323453524538345444454744550545536455664559745627456584568945717
4217896A101A1R1108120text114114138757590717575677546
5A102120150114114138757590717575677546
663668A103C1R34045564251454554424545404528
777706A104D1R4679371718675759071757567750
8A105E1R760678464647767678164676760670
9
10RateCode20232024202520262027
11R1186192198204210
12R2132136140144148
13R3106109112116119
14R48284879092
15R54749505253
16R63840434749
Sheet3 (2)
Cell Formulas
RangeFormula
K1:Y1K1=LET( rary, IFERROR(INDEX(B11:F16,XMATCH(RIGHT(J4:J8,2),$A$11:$A$16,0),XMATCH(YEAR(K3:Y3),B10:F10,0)),""), vis, MAP(J4:J8,LAMBDA(r,--(SUBTOTAL(103,r)=1))), res,BYCOL(SEQUENCE(,COLUMNS(K3:Y3)),LAMBDA(x, IF(AND(CHOOSECOLS(rary,x)=""),"",SUMPRODUCT(CHOOSECOLS(K4:Y8,x),CHOOSECOLS(rary,x),vis)))), res)
H4:H8H4=IFERROR(BYROW(J4:Y8,LAMBDA(br,SUM(MAP($J$3:$Y$3,br,LAMBDA(a,b,IF(AND(ISNUMBER(a),ISNUMBER(b)),b*XLOOKUP(RIGHT(INDEX(br,,1),2),$A$11:$A$16,XLOOKUP(YEAR(a),$B$10:$F$10,$B$11:$F$16)),0)))))),"")
Dynamic array formulas.
 
Upvote 1
Solution
I added error traps in both formulas to handle cases where blanks might appear, or text in the main table (see orange cells).
MrExcel_20231231.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXY
13072427945139162785239279256052560530726241742560525605235752641512244
2
3SUM ResultSkill/Rate4529245323453524538345444454744550545536455664559745627456584568945717
4217896A101A1R1108120text114114138757590717575677546
5A102120150114114138757590717575677546
663668A103C1R34045564251454554424545404528
777706A104D1R4679371718675759071757567750
8A105E1R760678464647767678164676760670
9
10RateCode20232024202520262027
11R1186192198204210
12R2132136140144148
13R3106109112116119
14R48284879092
15R54749505253
16R63840434749
Sheet3 (2)
Cell Formulas
RangeFormula
K1:Y1K1=LET( rary, IFERROR(INDEX(B11:F16,XMATCH(RIGHT(J4:J8,2),$A$11:$A$16,0),XMATCH(YEAR(K3:Y3),B10:F10,0)),""), vis, MAP(J4:J8,LAMBDA(r,--(SUBTOTAL(103,r)=1))), res,BYCOL(SEQUENCE(,COLUMNS(K3:Y3)),LAMBDA(x, IF(AND(CHOOSECOLS(rary,x)=""),"",SUMPRODUCT(CHOOSECOLS(K4:Y8,x),CHOOSECOLS(rary,x),vis)))), res)
H4:H8H4=IFERROR(BYROW(J4:Y8,LAMBDA(br,SUM(MAP($J$3:$Y$3,br,LAMBDA(a,b,IF(AND(ISNUMBER(a),ISNUMBER(b)),b*XLOOKUP(RIGHT(INDEX(br,,1),2),$A$11:$A$16,XLOOKUP(YEAR(a),$B$10:$F$10,$B$11:$F$16)),0)))))),"")
Dynamic array formulas.
Nice! I only had to use the first IFERROR() for it to run correctly. You are too good, thank you!
 
Upvote 0
You're welcome...glad to hear it's working okay.
 
Upvote 0
You're welcome...glad to hear it's working okay.
@KRice Not sure if I'm doing this correctly or not, but I want to thank you for guiding me to a solution for my problem. So, I liked one of your posts, and tagged you here. I certainly do not wish to hijack this thread.
In a QC application I need to average the last 3 test results. Straightforward, until the data becomes a filtered list so the the last three results are potentially separated by dozens if not hundreds of rows. Studying your solutions in this and other threads I now have a formula to extract the last three non-zero results:
Excel Formula:
=TAKE(FILTER(R$16:R1115,MAP(R$16:R1115,LAMBDA(r,--(SUBTOTAL(103,r)=1)))=1),-3)
or
Excel Formula:
=TAKE(FILTER(R16C[-4]:RC[-4],MAP(R16C[-4]:RC[-4],LAMBDA(r,--(SUBTOTAL(103,r)=1)))=1),-3)
From here it is trivial to wrap it all in AVERAGE(). And, easily modified to get the n value from a worksheet cell.
And- you also introduced me to LET which I had not yet stumbled across. That will be very useful.
So - Thank You!
 
Upvote 0
@Clif McIrvin, you made my day!...Yes, the FILTER function that relies on an array generated by MAP with an embedded SUBTOTAL(103,r)=1 condition is a clever way to work with visible cells in a filtered list. I'm glad to hear you were able to adapt the approach described here to your problem (you had a lot to read through to see the evolution of the idea)! Thank you for the update.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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