Dynamic Array with Total and Subtotals (FILTERXML)

DJunqueira

New Member
Joined
Dec 8, 2018
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hi all, just sharing a cool new way to use FILTERXML() to generate dynamic array with total and subtotals all in on cell formula. :)

In cell D7:D11 you can manipulate the range that the formula is calculating the total and subtotals. Very cool.

Formula with Total and Subtotals in a dynamic array.xlsx
ABCDEFGHIJKLMNOPQR
1
2
3Columns
46789 15913
5 x> 0 ; x < 549535761
6ConditionMatrix 5 x 465697377
7115913Subtotal115127139151
801721252917212529
903337414533374145
10149535761Subtotal50586674
11165697377Total165185205225
12
13
14165185205225
15
16115127139151
17
1850586674
19
20165185205225
21
22
Totalização horizontal
Cell Formulas
RangeFormula
F4:I4F4=COLUMN(F5:I5)
M4:Q11M4=IFERROR(INDEX(FILTERXML("<F><d>"&TEXTJOIN("</d><d>",0,FILTER(E7:I11,D7:D11,"NA"),"Subtotal",TRANSPOSE(MMULT(TRANSPOSE($F$7#*D7:D11)*ROW($F$7:$F$10)^0,ROW($F$7:$F$11)^0)),FILTER(E7:I11,D7:D11=0,"NA"),"Subtotal",TRANSPOSE(MMULT(TRANSPOSE($F$7#*ABS(D7:D11-1))*ROW($F$7:$F$10)^0,ROW($F$7:$F$11)^0)),"Total",TRANSPOSE(MMULT(TRANSPOSE($F$7#)*ROW($F$7:$F$10)^0,ROW($F$7:$F$11)^0)))&"</d></F>","//d"),SEQUENCE(ROWS(FILTER(E7:I11,D7:D11,"NA"))+1+ROWS(FILTER(E7:I11,D7:D11=0,"NA"))+2,5)),0)
F7:I11F7=SEQUENCE(5,4,1,4)
F14F14=SUMPRODUCT($F$7#*(COLUMN($F$7:$I$7)^0)*(--(F4#=COLUMN())))
G14G14=SUMPRODUCT($F$7#*(COLUMN($F$7:$I$7)^0)*(--(F4#=COLUMN())))
H14H14=SUMPRODUCT($F$7#*(COLUMN($F$7:$I$7)^0)*(--(F4#=COLUMN())))
I14I14=SUMPRODUCT($F$7#*(COLUMN($F$7:$I$7)^0)*(--(F4#=COLUMN())))
F16:I16F16=TRANSPOSE(MMULT(TRANSPOSE($F$7#*D7:D11)*ROW($F$7:$F$10)^0,ROW($F$7:$F$11)^0))
F18:I18F18=TRANSPOSE(MMULT(TRANSPOSE($F$7#*ABS(D7:D11-1))*ROW($F$7:$F$10)^0,ROW($F$7:$F$11)^0))
F20:I20F20=TRANSPOSE(MMULT(TRANSPOSE($F$7#)*ROW($F$7:$F$10)^0,ROW($F$7:$F$11)^0))
Dynamic array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
M4:Q14Expression=$M4="Total"textNO
M4:Q14Cell Value<>0textNO
M4:Q14Expression=$M4="Subtotal"textNO
Cells with Data Validation
CellAllowCriteria
D7:D11List1;0
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi

Hello
I found an alternative formula for Excel 365

Rich (BB code):
=LET(C,A7:A11,L,ROWS(C),S,SEQUENCE(L)^0,T,{1,1,1,1,1},R,B7:F11,K,IFERROR(INDEX(FILTERXML(""<t><s>""&TEXTJOIN(""</s><s>"",FALSE,FILTER(R,C=1,""""),TRANSPOSE(MMULT(TRANSPOSE(R*C)*T,S)),FILTER(R,C=0,""""),TRANSPOSE(MMULT(TRANSPOSE(R*NOT(C))*T,S)),TRANSPOSE(MMULT(TRANSPOSE(R)*T,S)))&""</s></t>"",""//s""),SEQUENCE(L+3,5)),""""),CHOOSE({1\2\2\2\2},IF(K=0,IF(SEQUENCE(L+3)<L+3,""????????"",""?????""),""""),K))
 
Upvote 0
Unfortunately I'm not in the Office Insider program, my Windows is still in the 7 version.
Tks any way, I saved the formula for when MS make it available for all.
 
Upvote 0

Forum statistics

Threads
1,223,986
Messages
6,175,793
Members
452,670
Latest member
nogarth

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