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?

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:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Give the SUBTOTAL function a try. Used like this it ignores filtered cells...assuming you are talking about using the Data>Filter feature.
Book1
ABCDEFGHIJKL
1Subtotal-->68881.568782309.67
2RateCode20232024202520262027SUM ResultCharge CodeSkill/RateJan-24Feb-24
3R1186.88192.4864198.261204.2088210.3351269685.2A101A1R1108.043548120.0484
4R2131.9135.857139.9327144.1307148.4546186573.3A102B1R281120
5R3105.99109.1697112.4448115.8181119.292773516.25A103C1R340.536290345.04032
6R482.0884.542487.0786789.6910392.3817690737.37A104D1R467.514516175.01613
7R547.2548.667550.1275351.6313553.1802947005.42A105E1R560.757258167.50806
Sheet1
Cell Formulas
RangeFormula
K1:L1K1=XLOOKUP(RIGHT($J3,2),$A$3:$A$7,XLOOKUP(YEAR(K$2),$B$2:$F$2,$B$3:$F$7))*SUBTOTAL(109,(K3:K7))
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)))))


Book1
ABCDEFGHIJKL
1Subtotal-->32491.859636102.07
2RateCode20232024202520262027SUM ResultCharge CodeSkill/RateJan-24Feb-24
3R1186.88192.4864198.261204.2088210.3351269685.2A101A1R1108.043548120.0484
7R547.2548.667550.1275351.6313553.1802947005.42A105E1R560.757258167.50806
Sheet1
Cell Formulas
RangeFormula
K1:L1K1=XLOOKUP(RIGHT($J3,2),$A$3:$A$7,XLOOKUP(YEAR(K$2),$B$2:$F$2,$B$3:$F$7))*SUBTOTAL(109,(K3:K7))
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)))))
 
Upvote 0
I think I missed something. The rate you've shown in the first row above the column headings applies only to the "R1" row (row 3)...so my offering won't work correctly. You'll need a corresponding list is filtered rates for any visible data.
 
Upvote 0
Ok...give this a try. We use a MAP function with SUBTOTAL to create an array of 0's and 1's to check whether a row is displayed. The other array is the product of rates and data values...and both arrays are then passed to SUMPRODUCT to get the sum of only those that are visible.
MrExcel_20231231.xlsx
ABCDEFGHIJKLM
1Subtotal-->34758.234542695.9753369.96
2RateCode20232024202520262027SUM ResultCharge CodeSkill/RateJan-24Feb-24Mar-24
3R1186.88192.4864198.261204.2088210.3351269685.2A101A1R1108.043548120.0484150.0605
4R2131.9135.857139.9327144.1307148.4546186573.3A102B1R281120150
7R547.2548.667550.1275351.6313553.1802947005.42A105E1R560.757258167.5080684.38508
Sheet1
Cell Formulas
RangeFormula
K1:M1K1=SUMPRODUCT(MAP(K3:K7,LAMBDA(r,--(SUBTOTAL(103,r)=1))),MAP($J$3:$J$7,K3:K7,LAMBDA(a,b,b*XLOOKUP(RIGHT(a,2),$A$3:$A$7,XLOOKUP(YEAR(K$2),$B$2:$F$2,$B$3:$F$7)))))
H3:H4,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)))))
 
Upvote 1
Ok...give this a try. We use a MAP function with SUBTOTAL to create an array of 0's and 1's to check whether a row is displayed. The other array is the product of rates and data values...and both arrays are then passed to SUMPRODUCT to get the sum of only those that are visible.
MrExcel_20231231.xlsx
ABCDEFGHIJKLM
1Subtotal-->34758.234542695.9753369.96
2RateCode20232024202520262027SUM ResultCharge CodeSkill/RateJan-24Feb-24Mar-24
3R1186.88192.4864198.261204.2088210.3351269685.2A101A1R1108.043548120.0484150.0605
4R2131.9135.857139.9327144.1307148.4546186573.3A102B1R281120150
7R547.2548.667550.1275351.6313553.1802947005.42A105E1R560.757258167.5080684.38508
Sheet1
Cell Formulas
RangeFormula
K1:M1K1=SUMPRODUCT(MAP(K3:K7,LAMBDA(r,--(SUBTOTAL(103,r)=1))),MAP($J$3:$J$7,K3:K7,LAMBDA(a,b,b*XLOOKUP(RIGHT(a,2),$A$3:$A$7,XLOOKUP(YEAR(K$2),$B$2:$F$2,$B$3:$F$7)))))
H3:H4,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)))))
Hi KRice, this is excellent, thank you. One Caveat. Your solution is working perfectly in the mini sheet (and I must say this is impressive), however in the operational file I`m using I am getting a #VALUE. The only thing I can see here is this equation may not be handling blank returns on column J. In my file this column is now a spilled array and reads into the formula as $J$2# instead of $J2:$J$7, and the column range for K:Z goes a fair number of rows deeper than results are being returned for ColumnJ. (i.e. the range for column K is approx. K2:K1000)

Is there a way we can add an IF="",0 error handling, or something equivalent into this solution?
 
Upvote 0
Ok...give this a try. We use a MAP function with SUBTOTAL to create an array of 0's and 1's to check whether a row is displayed. The other array is the product of rates and data values...and both arrays are then passed to SUMPRODUCT to get the sum of only those that are visible.
MrExcel_20231231.xlsx
ABCDEFGHIJKLM
1Subtotal-->34758.234542695.9753369.96
2RateCode20232024202520262027SUM ResultCharge CodeSkill/RateJan-24Feb-24Mar-24
3R1186.88192.4864198.261204.2088210.3351269685.2A101A1R1108.043548120.0484150.0605
4R2131.9135.857139.9327144.1307148.4546186573.3A102B1R281120150
7R547.2548.667550.1275351.6313553.1802947005.42A105E1R560.757258167.5080684.38508
Sheet1
Cell Formulas
RangeFormula
K1:M1K1=SUMPRODUCT(MAP(K3:K7,LAMBDA(r,--(SUBTOTAL(103,r)=1))),MAP($J$3:$J$7,K3:K7,LAMBDA(a,b,b*XLOOKUP(RIGHT(a,2),$A$3:$A$7,XLOOKUP(YEAR(K$2),$B$2:$F$2,$B$3:$F$7)))))
H3:H4,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)))))
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!

book1.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.
 
Last edited by a moderator:
Upvote 0
Could this solution be adapted to perform this same dynamic subtotaling, but instead of it`s sum results being a product of the column contents, multiplied by a lookup, the result would be a much simpler SUMIFS to a data table. This SUMIFS would use the date header as one criteria and the Charge Code (column I) as another criteria. Would only want to see the results in a single cell like in the above example, but when filtering on column J, we would obtain subtotal of the SUMIFS which is pulling from another sheet. Thoughts on this @KRice?
 
Upvote 0
Happy to help...and glad you got it working. Can you tell me more about the Skill/Rate column (col J)? You mentioned in practice that it is a spilled range, and referred to as $J$2#, yet your actual data needed for the formulas is in J3 and down. Does the formula delivering spilled J column results generate heading text (or a blank) in J2 and then the actual skill/rate codes in J3 and down, or is there is difference in table location between the worksheet snippet posted and your actual file? I'm trying to understand the #VALUE error you mentioned. Does your data table (columns K and to the right) sometimes have text in it?

Regarding your follow-on question, yes, I believe the same approach can be taken to deliver dynamic subtotals using other arrays; however, SUMIFS may not play well with this scheme, depending on how and where SUMIFS is used. Different functions might be necessary. What are the details?...I don't quite follow this:

...the result would be a much simpler SUMIFS to a data table. This SUMIFS would use the date header as one criteria and the Charge Code (column I) as another criteria.

What does this lookup table on the other sheet look like... where the date header and charge code would be used to find some other value(s). Are you saying that only those values in the other table---corresponding to where the matching conditions are met---would be summed?
 
Upvote 0
Happy to help...and glad you got it working. Can you tell me more about the Skill/Rate column (col J)? You mentioned in practice that it is a spilled range, and referred to as $J$2#, yet your actual data needed for the formulas is in J3 and down. Does the formula delivering spilled J column results generate heading text (or a blank) in J2 and then the actual skill/rate codes in J3 and down, or is there is difference in table location between the worksheet snippet posted and your actual file? I'm trying to understand the #VALUE error you mentioned. Does your data table (columns K and to the right) sometimes have text in it?

Regarding your follow-on question, yes, I believe the same approach can be taken to deliver dynamic subtotals using other arrays; however, SUMIFS may not play well with this scheme, depending on how and where SUMIFS is used. Different functions might be necessary. What are the details?...I don't quite follow this:



What does this lookup table on the other sheet look like... where the date header and charge code would be used to find some other value(s). Are you saying that only those values in the other table---corresponding to where the matching conditions are met---would be summed?
Hi KRice, to your first question I did a typo in my comment, it is a tezt header in J2 and a spilled range J3# down. The issue with the #VALUE results from your solution looking down but finding no return values after a certain point in column J (still within the set ranges within your equation). What Fluff`s ISNUMBER(b) is doing is effectively an IF(J="","") type of handling.

For the current problem - the data table is a series of columns containing a set of information, that when looked at across a given row forms a Unique ID and would look something like below. I have added the intended/concept SUMIFS above the date header row. Instead of one matching vertical criteria (charge code) however, it would of course be the entire list of Charge Code. In the operational file, and without consideration to the dynamic filtering we are trying to achieve, the only SUM criteria is the dates and as such I am currently using a SUMIF to pull the data. Now what we want to do is take the same SUMIF by date, but be able to filter by charge code.

book1.xlsm
ABCDEFGHIJKLMNOPQRSTU
1192.4864192.4864192.4864192.4864192.4864192.4864192.4864192.4864192.4864192.4864192.4864192.4864192.4864192.4864192.4864
2DateCharge CodeHourCharge CodeSkill/RateJan-24Feb-24Mar-24Apr-24May-24Jun-24Jul-24Aug-24Sep-24Oct-24Nov-24Dec-24Jan-25Feb-25Mar-25
3Jan-24A101192.5A101A1R1108120150114114138757590717575687547
4Feb-24A102135.9A102B1R281120150114114138757590717575687547
5Mar-24A103109.2A103C1R3414556434352454554434545414528
6Apr-24A10484.5A104D1R468759471718675759071757568750
7May-24A10548.7A105E1R561688464647868688164686861680
Sheet1
Cell Formulas
RangeFormula
G1:U1G1=SUMIFS($C:$C,$A:$A,$G$2,$B:$B,$E$3)
 
Last edited by a moderator:
Upvote 0
Hi KRice, I was editing the post to add clarity but it timed out.

I want to add that in the operational file the date header row is another set of criteria (AA,BB,CC,DD etc), this will not change the solution we are after I just wanted to mention this so you don`t start wondering why we are not just pulling the data onto the example sheet 1:1. I used dates as it was consistent with the fist soltuion.

I am trying to create a dynamic matrix where a user can filter on charge code and obtain a set of filtered rollup data based on the header criteria. Let me know if you have further questions, thank you for you help!
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
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