AGGR

AGGR(a,fn,[kn])
a
array
fn
function nr. 1<=fn<=22
[kn]
can be omitted for functions that do not require 2nd argument

Aggregate By Rows NEW !! ISOMITTED, BYROW , SCAN , MAKEARRAY at work !!

Xlambda

Well-known Member
Joined
Mar 8, 2021
Messages
837
Office Version
  1. 365
Platform
  1. Windows
AGGR Aggregate By Rows 22 Excel functions, can handle array arguments. !! NEW !! functions ISOMITTED , BYROW , SCAN , MAKEARRAY used
Similar to AAGGREGATE but does not need recursion.
Calls A1GGR(a,fn,[k])=LAMBDA(a,fn,[k],BYROW(a,LAMBDA(a,IFS(fn<14,SWITCH(fn,1,AVERAGE(a),2,COUNT(a),3,SUM(--(a<>"")),4,MAX(a),5,MIN(a),6,PRODUCT(a),7,STDEV.S(a),8,STDEV.P(a),9,SUM(a),10,VAR.S(a),11,VAR.P(a),12,MEDIAN(a),13,MODE.SNGL(a)),fn<=19,AGGREGATE(fn,6,a,k),fn=20,AND(a),fn=21,OR(a),fn=22,XOR(a),TRUE,"check arg"))))
A1GGR function could have been integrated in the main one, but I have kept it separate because is much easier to add excel or custom made functions anytime we want.
We simply add the function inside A1GGR at the very end of formula , just before "TRUE" (
...,fn=23,CUSTOM(a,k),TRUE,"check arg"...)and change "nf" variable inside AGGR with total count of fn, "nf" variable, first variable after LET, that's all.
Excel Formula:
=LAMBDA(a,fn,[kn],
    LET(nf,22,cd,ISOMITTED(kn),k,IF(cd,0,kn),rw,ROWS(a),cl,COLUMNS(fn),ck,COLUMNS(k),s,SCAN(0,fn,LAMBDA(v,a,v+(a>13)*(a<20))),
      m,MAX(s),IFS(OR(ISNA(XMATCH(fn,SEQUENCE(,nf)))),"check fn",AND(NOT(cd),m<>ck),"check kn",TRUE,LET(kk,INDEX(k,s),
        MAKEARRAY(rw,cl,LAMBDA(r,c,LET(x,INDEX(fn,c),y,INDEX(kk,c),z,TRANSPOSE(A1GGR(a,x,y)),IFNA(INDEX(z,r),""))))))
    )
)
LAMBDA 1.1.1.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZ
122 functionsNEW!! Functions used BYROW, SCAN, MAKEARRAY, ISOMITTED
2fn argumentA1GGR: Array 1 (single 1D results array, because of BYROW functionality) that can Aggregate 22 functions, by each row (single value arguments)
3functionNote 1: This function could have been integrated in the main one, but I have kept it separate because is much easier to add excel or custom made functions anytime we want.
41AverageWe simply add the function inside A1GGR at the end of SWITCH formula, and change "nf" variable inside AGGR with total count of fn, "nf" variable, first variable after LET, that's all.
52CountNote 2: Did not use AGGREGATE function for fn [1,13] because of its range syntax. They can not handle array arguments. fn [13,19] do handle array arguments.
63CountaSimilar to AAGGREGATE but no recursion
74Maxfn,1,kn,omittedfn,9,kn,omittedfn,14,kn,2
85Minsample=A1GGR(D9:M14,1)=A1GGR(D9:M14,9)=A1GGR(D9:M14,14,2)
96Product1 3a36b23104286
107Stdev.S3d76f-41195.333329
118Stdev.P5c-4c-3d-3080.535
129Sum9-54112rtw74.667289
1310Var.S113 5xx5866.333388
1411Var.Ps-253 040510605
1512Median
1613Mode.Snglmeaning of knAGGR: Aggregate Array by Rows, can handle array arguments, 22 functions
1714LargeReturn the kn'th largest value
1815SmallReturn the kn'th smallest valuefn,sequence(,13),kn,omitted
1916Percentile.IncReturn the kn'th percentile0<=kn<=1=AGGR(D9:M14,SEQUENCE(,13))
2017Quartile.IncReturn the kn'th quartile0<=kn<=4(<5)47910132403.0552.828289.333833
2118Percentile.ExcReturn the kn'th percentile0<kn<15.3336811-4-498965.3174.8533228.2723.566.5
2219Quartile.ExcReturn the kn'th quartile1<=kn<=3(<4)0.5698-404.934.5324.320.25-1.5-3
2320AND4.6676912-5-151206.0885.5582837.0730.895.5
2421ORfn,kn syntax6.33368113396002.8052.56387.8676.5565.55
2522XORnr. of kn arg.=nr.fn arg. that require kn106753-2021.2319.3860450.8375.720
26Examples:
27fn={1,2,15,9,14,3,18} kn={2,3,0.5} is ok=SEQUENCE(,6,14)
28if we need to extract average,3rd and 2nd largest,sumfn141516171819
29fn={1,14,14,9} kn will be {3,2}fn,{21,22,23},kn,omittedkn220.220.22
30=AGGR(D9:M14,{1,14,14,9},{3,2})sample=AGGR(J31:L33,{20,21,22})=AGGR(D9:M14,S28#,S29:X29)
3143628TRUETRUETRUETRUETRUETRUE622.231.63
325.3337932FALSETRUETRUEFALSETRUEFALSE9336.5-1.26.5
330.5053FALSEFALSEFALSEFALSEFALSEFALSE5-3-3-1.5-3.6-1.5
344.66779289115.5-2.65.5
356.33368388555.53.85.5
361045605002-1.22
37if N(kn)<>N(fn,13<fn<20)complex fn,kn arguments
38=AGGR(D9:M14,{2,15,15,12,14},{2,3})kn is 1val.shortfn,{1,10,11,14,14,15,15},kn,{2,3,2,3}
39check kn=AGGR(D9:M14,{1,10,11,14,14,15,15},{2,3,2,3})
40if fn out of range49.33386323
41=AGGR(D9:M14,{1,2,3,23})5.33328.2723.569736
42check fn0.524.320.2550-3-3
43if kn out of range (kn for fn=18 ,should be<1)4.66737.0730.899714
44=AGGR(D9:M14,{16,18},{1,1})6.3337.8676.5568655
4510#NUM!10450.8375.75400
4611#NUM!
478#NUM!
4812#NUM!
4911#NUM!
5053#NUM!
51
AGGR post
Cell Formulas
RangeFormula
O8,R8,U8,D44,D41,L39,D38,S30,N30,D30,S27,K19O8=FORMULATEXT(O9)
E9,G14,F13E9=""
O9:O14O9=A1GGR(D9:M14,1)
R9:R14R9=A1GGR(D9:M14,9)
U9:U14U9=A1GGR(D9:M14,14,2)
K20:W25K20=AGGR(D9:M14,SEQUENCE(,13))
S28:X28S28=SEQUENCE(,6,14)
D31:G36D31=AGGR(D9:M14,{1,14,14,9},{3,2})
N31:P33N31=AGGR(J31:L33,{20,21,22})
S31:X36S31=AGGR(D9:M14,S28#,S29:X29)
D39D39=AGGR(D9:M14,{2,15,15,12,14},{2,3})
L40:R45L40=AGGR(D9:M14,{1,10,11,14,14,15,15},{2,3,2,3})
D42D42=AGGR(D9:M14,{1,2,3,23})
D45:E50D45=AGGR(D9:M14,{16,18},{1,1})
Dynamic array formulas.
 
Last edited by a moderator:
Upvote 0
Note to moderators: Very first row of the post, the one reserved for array syntax does not allow "[kn]", optional argument syntax between brackets.
AGGR(a,fn,[kn]) should be read . Who would have thought that Excel will introduce this ?!! ?✌
 
Note to moderators: Very first row of the post, the one reserved for array syntax does not allow "[kn]", optional argument syntax between brackets.
AGGR(a,fn,[kn]) should be read . Who would have thought that Excel will introduce this ?!! ?✌
Solved !! by smozgur in 0.1 sec . ?✌
 
Actually, it took a couple of hours as I didn't see your message in this thread. :)
Thanks for catching this quickly.
 

Forum statistics

Threads
1,216,505
Messages
6,131,026
Members
449,616
Latest member
PsychoCube

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