ASUBTOT

=ASUBTOT(a,n,cl,ctx)

a
array
n
integer, every n-th row subtotal row will be inserted, dynamic if main dynamic array or table grows or shrinks, no refresh
cl
integer or constant array of integers, columns indexes that will be summed
ctx
integer, column index where text string "SubTotal" will be placed, 0 or ignored will take 1 value

array subtotal, inserts sum subtotal rows, every n-th rows of an array

Xlambda

Well-known Member
Joined
Mar 8, 2021
Messages
860
Office Version
  1. 365
Platform
  1. Windows
ASUBTOT array subtotal, inserts sum subtotal rows, every n-th rows of an array. calls ARUNTOT , AUNSTACK , ASTACK
- with cl argument we can choose what columns will be summed {2,4,5} or simple ,3
- ctx - column index where "SubTotal" text string will be placed, if we want to change this text, in the formula is the first variable after LET.
Other function used on the minisheet to check the results APIVOT
Excel Formula:
=LAMBDA(a,n,cl,ctx,
    LET(tx,"SubTotal",k,INT(ABS(n)),ct,MAX(1,ctx),r,ROWS(a),c,COLUMNS(a),s,SEQUENCE(c),
       au,AUNSTACK(IF(a="","",a),k),at,ARUNTOT(au,),t,INDEX(at,k,),m,MOD(SEQUENCE(,COLUMNS(t))-1,c)+1,
       xm,XMATCH(m,cl),x,IF(ISNA(xm),"",t),y,IF(m=ct,tx,x),u,IF(SEQUENCE(k+1)=k+1,y,au),as,ASTACK(u,c),z,MMULT(--(as<>""),s^0),
       ca,AND(ISNUMBER(XMATCH(cl,s)),ISNUMBER(XMATCH(ct,s))),
       IF(NOT(ca),"check clm values",FILTER(as,z))
    )
)
LAMBDA 7.0.xlsx
ABCDEFGHIJKLMNOPQRSTU
1sample any data=ASUBTOT(A2:D16,6,{3,4},)=ASUBTOT(A2:D16,4,{1,2,3},4)=ASUBTOT(A2:D16,10,4,2)
2e33dn=6e33dn=4e33dn=10e33d
33hhfcl={3,4}3hhfcl={1,2,3}3hhfcl=43hhf
4t5f1ctx ,t5f1ctx=4t5f1ctx=2t5f1
5y2yy2yy2yy2y
6u74u74385SubTotalu74
7iv58iv58u74iv58
8o9zrSubTotal149iv58o9zr
96g8to9zro9zr6g8t
101436g8t6g8t143
11esu14361617SubTotalesu
12738iesu143SubTotal12
13td95738iesu738i
1425pwtd95738itd95
15u649SubTotal298td9525pw
16i85r25pw7421SubTotalu649
17u64925pwi85r
18i85ru649SubTotal14
19SubTotal99i85r
202199SubTotal
21other functions on minisheetAPIVOT
22sampleH24=ASUBTOT(A24:F43,4,{4,5},2)check
23Year/QtrProdunit pricenr.u soldtotObsYear/QtrProdunit pricenr.u soldtotObs=APIVOT(A24:F43,1,2,5,)
2420 Qtr 1P15840d20 Qtr 1P15840d(1\2) 5 vf=0P1P2P3P4Grand Total
2520 Qtr 1P23721f20 Qtr 1P23721f20 Qtr 140211848127
2620 Qtr 1P36318v20 Qtr 1P36318v20 Qtr 245123616109
2720 Qtr 1P48648b20 Qtr 1P48648b20 Qtr 325307256183
2820 Qtr 2P15945tSubTotal2412720 Qtr 445123640133
2920 Qtr 2P23412j20 Qtr 2P15945t21 Qtr 14594240136
3020 Qtr 2P36636d20 Qtr 2P23412jGrand Total20084204200688
3120 Qtr 2P48216t20 Qtr 2P36636d
3220 Qtr 3P15525u20 Qtr 2P48216t=APIVOT(A24:F43,1,2,4,)
3320 Qtr 3P231030ySubTotal21109(1\2) 4 vf=0P1P2P3P4Grand Total
3420 Qtr 3P361272s20 Qtr 3P15525u20 Qtr 1873624
3520 Qtr 3P48756x20 Qtr 3P231030y20 Qtr 2946221
3620 Qtr 4P15945j20 Qtr 3P361272s20 Qtr 351012734
3720 Qtr 4P23412d20 Qtr 3P48756x20 Qtr 4946524
3820 Qtr 4P36636uSubTotal3418321 Qtr 1937524
3920 Qtr 4P48540r20 Qtr 4P15945jGrand Total40283425127
4021 Qtr 1P15945d20 Qtr 4P23412d
4121 Qtr 1P2339a20 Qtr 4P36636u
4221 Qtr 1P36742f20 Qtr 4P48540r
4321 Qtr 1P48540sSubTotal24133
4421 Qtr 1P15945d
4521 Qtr 1P2339a
4621 Qtr 1P36742f
4721 Qtr 1P48540s
48SubTotal24136
49
ASUBTOT post
Cell Formulas
RangeFormula
F1,O32,O23,P1,K1F1=FORMULATEXT(F2)
F2:I19F2=ASUBTOT(A2:D16,6,{3,4},)
K2:N20K2=ASUBTOT(A2:D16,4,{1,2,3},4)
P2:S18P2=ASUBTOT(A2:D16,10,4,2)
I22I22=FORMULATEXT(H24)
H24:M48H24=ASUBTOT(A24:F43,4,{4,5},2)
O24:T30O24=APIVOT(A24:F43,1,2,5,)
O33:T39O33=APIVOT(A24:F43,1,2,4,)
E24:E43E24=D24*C24
Dynamic array formulas.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,954
Messages
6,175,603
Members
452,660
Latest member
Zatman

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