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

Canadarm3 Labour_Planning_O365_v1.3.1.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)))))
 
So that array is the lookup array used by MATCH. Broaden that formula bar selection to include the entire MATCH function to see if you get numbers and errors (where matches exist and do not exist). And are those 0’s at the end expected?…are those cells blank or 0?

Tell me about the K and R contents…what do they look like?
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
So that array is the lookup array used by MATCH. Broaden that formula bar selection to include the entire MATCH function to see if you get numbers and errors (where matches exist and do not exist). And are those 0’s at the end expected?…are those cells blank or 0?

Tell me about the K and R contents…what do they look like?

Slight update. Something went astray and the file crashed. working from the backup, same starting point, same equations and ranges, but now this is before I started messing with excels suggested error corrections. I now get the following after inspection:

Filter - all FALSE
ISNUMBER - returns a single #VALUE
K4:K8=R3 - all FALSE

Entire MATCH - returns all `VALUE plus this odd symbol at the end
1704308156957.png


Here is the equation out of the file in it's current state for reference. Note: M = R, C=P.

=SUM(('Ref Data'!$N2:$N1300)*('Ref Data'!$K2:$K1300=M$10)*ISNUMBER(MATCH('Ref Data'!$B2:$B1300,FILTER($C$11#,MAP(C11#,LAMBDA(r,--(SUBTOTAL(103,r)=1)))),0)))

What I can say about the header row (R) is that it is pulling named ranged that contains text, and is doing so via TRANSPOSE (p.s. I did test this out on the mini sheet were your equation is working to validate that the named range and array formula are not impacting).

For K, it is all text. 90% of column is populated, with the last 10% or so being empty.
 
Upvote 0
Further update - I misspoke

I think the issue might be have something to do with the range the header data is being pulled from: When I test the TRANSPOSE(named range) on the mini sheet header row, it causes the equation to go to zeros. If I use TRANSPOSE() to pull the list of headers from an on sheet table it works. closer?
 
Last edited:
Upvote 0
Further update - I misspoke

I think the issue might be have something to do with the range the header data is being pulled from: When I test the TRANSPOSE(named range) on the mini sheet header row, it causes the equation to go to zeros. If I use TRANSPOSE() to pull the list of headers from an on sheet table it works. closer?
And it's not even that. replaced everything with text and it continues to work on the mini sheet, but not in the file. stumped
 
Upvote 0
This is difficult to debug without being able to examine the file. I'll try to mock up something that's structured closer to your workbook. Something is tying up Excel, as my version is hanging after pasting your minisheet from post #22. I'll have to force-stop and construct step-by-step. So each row is grabbing information from a separate worksheet using INDIRECT? And the Ref Data worksheet, columns B, K,and N...is there anything unusual about the contents of those columns?
 
Upvote 0
One thing I notice...the FILTER/MAP references are supposed to be fixed references. The spilling range you've entered in one place is not fixed. Change that to look like the other...$C$11#, otherwise as that formula is copied across the row, the range will change.
 
Upvote 1
Hi KRice, ok so you got it. it works! Turns out there were two issues. One was as you identified, the C11# not being fixed. The other is that I was using COL:COL referencing as I mentioned much earlier. When I change the column referencing to a fixed size array it works! It's only slightly unfortunate as the user will need to be careful that the range for this equation is always => the reference data. Mind you a small price to pay for the functionality your solution provides.

Can't thank you enough for all your work on this!
 
Upvote 0
Scrap my first reply, we got it. I used the technique provided by @Fluff for this error handling IF(ISNUMBER(b), to fix this. You guys are too good! Thanks so much!

Canadarm3 Labour_Planning_O365_v1.4.1..xlsm
ABCDEFGHIJKLMNOPQRSTUVWXY
144891.4153955.0567443.8251257.351257.362048.3139179.639179.647015.5237220.6239179.639179.636319.4940354.9919035.26
2RateCode20232024202520262027SUM ResultSkill/RateJan-24Feb-24Mar-24Apr-24May-24Jun-24Jul-24Aug-24Sep-24Oct-24Nov-24Dec-24Jan-25Feb-25Mar-25
3R1186.9192.5198.3204.2210.3260379.7A101A1R1108120150114114138757590717575687547
4R2131.9135.9139.9144.1148.5180013.9A102B1R281120150114114138757590717575687547
5R3106.0109.2112.4115.8119.370348.1A103C1R3414556434352454554434545414528
6R482.184.587.189.792.490735.6A104D1R468759471718675759071757568750
7R547.348.750.151.653.247004.9A105E1R561688464647868688164686861680
Sheet1
Cell Formulas
RangeFormula
K1:Y1K1=SUMPRODUCT(MAP(K3:K7,LAMBDA(r,--(SUBTOTAL(103,r)=1))),MAP($J$3:$J$7,K3:K7,LAMBDA(a,b,IF(ISNUMBER(b),b*XLOOKUP(RIGHT(a,2),$A$3:$A$7,XLOOKUP(YEAR(K$2),$B$2:$F$2,$B$3:$F$7))))))
H3:H7H3=BYROW(J3:X7,LAMBDA(br,SUM(MAP($J$2:$X$2,br,LAMBDA(a,b,IF(ISNUMBER(b),b*XLOOKUP(RIGHT(INDEX(br,,1),2),$A$3:$A$7,XLOOKUP(YEAR(a),$B$2:$F$2,$B$3:$F$7)),0))))))
Dynamic array formulas.
Hi KRice, what would it take to have the K1 equation spill to the right? I tried wrapping it in a BYCOL, but the numbers don't quite add up. Seems like the mapping to the Year lookup may not be returned correctly.
 
Upvote 0
I suppose you could think about this as having three components:
  1. a rate array that maps entirely to the main table (rary),
  2. a visibility column array that determines which rows should be retained or zeroed (vis),
  3. a final BYCOL calculation that steps sequentially over column indexes of the main table (K4:Y8), passing the vis array and the ith columns of rary and the main table to SUMPRODUCT.
MrExcel_20231231.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXY
144891.453955.167443.851257.351257.362048.339179.639179.647015.537220.639179.639179.636319.540355.019035.3
2
3SUM ResultSkill/Rate452924532345352453834541345444454744550545536455664559745627456584568945717
4260379.7A101A1R1108120150114114138757590717575687547
5180013.9A102B1R281120150114114138757590717575687547
670348.07A103C1R3414556434352454554434545414528
790735.62A104D1R468759471718675759071757568750
847004.91A105E1R561688464647868688164686861680
9
10RateCode20232024202520262027
11R1186.9192.5198.3204.2210.3
12R2131.9135.9139.9144.1148.5
13R3106.0109.2112.4115.8119.3
14R482.184.587.189.792.4
15R547.348.750.151.653.2
Sheet3 (2)
Cell Formulas
RangeFormula
K1:Y1K1=LET( rary, INDEX(B11:F15,XMATCH(RIGHT(J4:J8,2),$A$11:$A$15,0),XMATCH(YEAR(K3:Y3),B10:F10,0)), vis, MAP(J4:J8,LAMBDA(r,--(SUBTOTAL(103,r)=1))), BYCOL(SEQUENCE(,COLUMNS(K3:Y3)),LAMBDA(x, SUMPRODUCT(CHOOSECOLS(K4:Y8,x),CHOOSECOLS(rary,x),vis))))
H4:H8H4=BYROW(J4:X8,LAMBDA(br,SUM(MAP($J$3:$X$3,br,LAMBDA(a,b,IF(ISNUMBER(b),b*XLOOKUP(RIGHT(INDEX(br,,1),2),$A$11:$A$15,XLOOKUP(YEAR(a),$B$10:$F$10,$B$11:$F$15)),0))))))
Dynamic array formulas.
 
Upvote 0
I suppose you could think about this as having three components:
  1. a rate array that maps entirely to the main table (rary),
  2. a visibility column array that determines which rows should be retained or zeroed (vis),
  3. a final BYCOL calculation that steps sequentially over column indexes of the main table (K4:Y8), passing the vis array and the ith columns of rary and the main table to SUMPRODUCT.
MrExcel_20231231.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXY
144891.453955.167443.851257.351257.362048.339179.639179.647015.537220.639179.639179.636319.540355.019035.3
2
3SUM ResultSkill/Rate452924532345352453834541345444454744550545536455664559745627456584568945717
4260379.7A101A1R1108120150114114138757590717575687547
5180013.9A102B1R281120150114114138757590717575687547
670348.07A103C1R3414556434352454554434545414528
790735.62A104D1R468759471718675759071757568750
847004.91A105E1R561688464647868688164686861680
9
10RateCode20232024202520262027
11R1186.9192.5198.3204.2210.3
12R2131.9135.9139.9144.1148.5
13R3106.0109.2112.4115.8119.3
14R482.184.587.189.792.4
15R547.348.750.151.653.2
Sheet3 (2)
Cell Formulas
RangeFormula
K1:Y1K1=LET( rary, INDEX(B11:F15,XMATCH(RIGHT(J4:J8,2),$A$11:$A$15,0),XMATCH(YEAR(K3:Y3),B10:F10,0)), vis, MAP(J4:J8,LAMBDA(r,--(SUBTOTAL(103,r)=1))), BYCOL(SEQUENCE(,COLUMNS(K3:Y3)),LAMBDA(x, SUMPRODUCT(CHOOSECOLS(K4:Y8,x),CHOOSECOLS(rary,x),vis))))
H4:H8H4=BYROW(J4:X8,LAMBDA(br,SUM(MAP($J$3:$X$3,br,LAMBDA(a,b,IF(ISNUMBER(b),b*XLOOKUP(RIGHT(INDEX(br,,1),2),$A$11:$A$15,XLOOKUP(YEAR(a),$B$10:$F$10,$B$11:$F$15)),0))))))
Dynamic array formulas.
Hey, as always thank you for the clear insights. I have the equation in place but an getting #N/A. Do we need to add back the ISNUMBER to handle the empty cells that can occur in both the header row and column J?
 
Upvote 0

Forum statistics

Threads
1,215,071
Messages
6,122,964
Members
449,094
Latest member
Anshu121

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