ASCAN

ASCAN(a,[d])
a
array
[d]
direction argument ; 0 or omitted scan by array, -1 by rows, 1 by clms

Array SCAN, 3 in 1 function, SCAN by row, by column, by array

Xlambda

Well-known Member
Joined
Mar 8, 2021
Messages
860
Office Version
  1. 365
Platform
  1. Windows
ASCAN, Array SCAN, 3 in 1 function, SCAN by row, by column, by array. This is my take of tboulden's SCANBYROW/BYCOL.
Uses only new!! SCAN lambda helper function, no need of byrow,bycol,makearray, or lambda as arguments.
Excel Formula:
=LAMBDA(a,[d],
    LET(y,IF(d=1,TRANSPOSE(a),a),s,SCAN(0,y,LAMBDA(v,a,v+a)),r,ROWS(s),c,COLUMNS(s),sr,SEQUENCE(r)-1,
       x,s-IF(d,IFERROR(INDEX(INDEX(s,,c),sr)*sr^0,0),0),
       IF(d=1,TRANSPOSE(x),x)
   )
)
LAMBDA 1.1.3.xlsx
ABCDEFGHIJKLMNOPQRST
1d,omitted (by array)d,-1 (by rows)d,1 (by clms)
2sample 1a=ASCAN(A3:D6)=ASCAN(A3:D6,-1)=ASCAN(A3:D6,1)
3123413610136101234
45678152128365111826681012
5910111245556678919304215182124
613141516911051201361327425828323640
7
8d,omitted (by array)d,-1 (by rows)d,1 (by clms)
9sample 2a=ASCAN(A10#)=ASCAN(A10#,-1)=ASCAN(A10#,1)
10123413610136101234
115678152128365111826681012
12910111245556678919304215182124
1313141516911051201361327425828323640
14171819201531711902101735547445505560
15212223242312532763002143669066727884
16
17Note: Did not set an extra argument for any kind of "initial value", since the only thing it does is too simple,
18adds a constant value to the final outcome , like in 10+ASCAN(a)
19
ASCAN post
Cell Formulas
RangeFormula
F2,P9,K9,F9,P2,K2F2=FORMULATEXT(F3)
F3:I6F3=ASCAN(A3:D6)
K3:N6K3=ASCAN(A3:D6,-1)
P3:S6P3=ASCAN(A3:D6,1)
A10:D15A10=SEQUENCE(6,4)
F10:I15F10=ASCAN(A10#)
K10:N15K10=ASCAN(A10#,-1)
P10:S15P10=ASCAN(A10#,1)
Dynamic array formulas.
 
Upvote 0
Inspired by latest Mr.Excel YT (7-Apr-2022): Find Next True And The Matching Records Above And Below - 2480
It's not about reduce or scan techniques, is about defining an "inside" lambda that can be called by an argument value of main function.
Challenge description:
"Michele has 46000 rows of data. Each ID has several records in a row. Many records are marked as "Changed". When there is a change, Michele needs to check the record marked, plus the matching IDs just above and below. In this video, I try Find All and 2 Advanced Filters. I bet you have something better."
A lambda that solves the challenge:
IDIXFLT(ar,[n] ID Index Filter function, can handle unsorted array, or TRUE dups for same ID's
ar: array
[n]: integer
- if n omitted or n=0, function returns total nr. of matches and the list of all matched ID's
- if 1<=n<=t (total nr. of unique matches), function returns as 1st clm, an array of rows indexes stacked horizontally to records extraction (all fields) of respective "n" value
- if n>t => n=t
- if n<0 => n=abs( n )
Excel Formula:
=LAMBDA(ar, [n],
    LET(
        a, IF(ar = "", "", ar),
        id, INDEX(a, , 2),
        tc, INDEX(a, , 4),
        ft, IF(tc = TRUE, 1, 0),
        f, SORT(UNIQUE(FILTER(id, ft))),
        t, ROWS(f),
        s, SEQUENCE(ROWS(a)),
        z, LAMBDA(k,
            LET(
                x, INDEX(f, k),
                y, id = x,
                SORT(HSTACK(FILTER(s, y), FILTER(a, y)))
            )
        ),
        IF(n, z(MIN(ABS(n), t)), IFNA(HSTACK(t, f), ""))
    )
)
part of defining the lambda z(k), variable "z" :
z,LAMBDA(k,LET(x,INDEX(f,k),y,id=x,SORT(HSTACK(FILTER(s,y),FILTER(a,y)))))
part of calling z( n ), where "n" is one of main's function argument :
z(MIN(ABS( n ),t))
Mr.Excel 2480 challenge 2nd draft.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAAB
1sample array, sortedsample array, unsorted
2no TRUE dupshas TRUE dups for same IDindex arrayomitted or 0n,1n,3
3=SEQUENCE(ROWS(F4:I35))=IDIXFLT(F4:I35)=IDIXFLT(F4:I35,1)=IDIXFLT(F4:I35,3)
41761Q70913521763Q709135215E373692031E3736171122124L6272643TRUE
51762Q70915341764Q7091534TRUE2H7453102032E3736388TRUE132125L6272565
61763Q70915651765Q70915653L6272112033E3736196
71764Q7091631TRUE1922X39146314Q7091↑↑↑n,4
81765Q70915021923X3914502TRUE5X3914first clm, all rows indexes of first id match (for n=1)=IDIXFLT(F4:I35,4)
91766Q70912191924X39142196↑↑11763Q7091352
101917X39142131967H7453213TRUE7top left cell, total nr. matches and their values21764Q7091534TRUE
111918X39142481968H74532488n,231765Q7091565
121919X39141712031E37361719=IDIXFLT(F4:I35,2)141766Q7091365
131920X39143882032E3736388TRUE1071967H7453213TRUE271761Q7091291
141921X39141962033E37361961181968H7453248281762Q7091457
151922X39146432124L6272643TRUE12171972H7453721
161923X3914565TRUE2125L627256513181973H7453444n,5
171924X39143651766Q709136514191974H7453491=IDIXFLT(F4:I35,5)
181967H7453708TRUE1917X391470815201975H745324441922X3914631
191968H74536051918X391460516241969H745362351923X3914502TRUE
201969H74537211972H745372117TRUE251970H745361461924X3914219
211970H74534441973H745344418duplicates TRUE261971H7453239151917X3914708
221971H74534911974H745349119for same ID "X3914"291976H7453351161918X3914605
231972H74532441975H745324420301977H7453305211919X3914568
241973H74535681919X391456821311978H7453683221920X3914331TRUE
251974H74533311920X3914331TRUE22321979H7453395231921X3914236
261975H74532361921X391423623
271976H74536231969H745362324calling the function for sorted array A4:D35
281977H74536141970H745361425n,omittedn,5n,-100 => n=abs(n)=100 > 5 => n=5
291978H74532391971H745323926=IDIXFLT(A4:D35)=IDIXFLT(A4:D35,5)=IDIXFLT(F4:I35,-100)
301979H74532911761Q7091291275E373671917X391421341922X3914631
312031E37364571762Q709145728H745381918X391424851923X3914502TRUE
322032E3736351TRUE1976H745335129L627291919X391417161924X3914219
332033E37363051977H745330530Q7091101920X3914388151917X3914708
342124L6272683TRUE1978H745368331X3914111921X3914196161918X3914605
352125L62723951979H745339532121922X3914643211919X3914568
36131923X3914565TRUE221920X3914331TRUE
37141924X3914365231921X3914236
38
39As we see, both arrays, sorted and unsorted return same values, but of course,
40as 1st clm, the array of row indexes, is different
41Also, notice that sorted array has no TRUE dups.
42
last draft
Cell Formulas
RangeFormula
K3,N3,Q3,W29,N29,Q29,W17,Q12,W8,W3K3=FORMULATEXT(K4)
K4:K35K4=SEQUENCE(ROWS(F4:I35))
N4:O8N4=IDIXFLT(F4:I35)
Q4:U6Q4=IDIXFLT(F4:I35,1)
W4:AA5W4=IDIXFLT(F4:I35,3)
W9:AA14W9=IDIXFLT(F4:I35,4)
Q13:U25Q13=IDIXFLT(F4:I35,2)
W18:AA25W18=IDIXFLT(F4:I35,5)
N30:O34N30=IDIXFLT(A4:D35)
Q30:U37Q30=IDIXFLT(A4:D35,5)
W30:AA37W30=IDIXFLT(F4:I35,-100)
Dynamic array formulas.
 
Mr.Excel 2480 challenge 2nd draft.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1samplesimulation for 100000 rows, dealing with whole array comparison and no iterations involved, function speed is lighting fast.
21761Q7091352=SEQUENCE(100000)check results array nr. rows
31762Q7091534↓↓↓↓=MOD(F4#-1,ROWS(A2:D33))+1=INDEX(IF(A2:D33="","",A2:D33),G4#,SEQUENCE(,4))=IDIXFLT(I4#)=IDIXFLT(I4#,5)=ROWS(R4#)
41763Q7091565111761Q70913525E373671917X391421325000
51764Q7091631TRUE221762Q7091534H745381918X3914248
61765Q7091502331763Q7091565L627291919X3914171
71766Q7091219441764Q7091631TRUEQ7091101920X3914388
81917X3914213551765Q7091502X3914111921X3914196
91918X3914248661766Q7091219121922X3914643
101919X3914171771917X3914213check rows131923X3914565TRUE
111920X3914388881918X3914248=ROWS(I4#)141924X3914365
121921X3914196991919X3914171100000391917X3914213
131922X391464310101920X3914388401918X3914248
141923X3914565TRUE11111921X3914196411919X3914171
151924X391436512121922X3914643421920X3914388
161967H7453708TRUE13131923X3914565TRUE431921X3914196
171968H745360514141924X3914365441922X3914643
181969H745372115151967H7453708TRUE451923X3914565TRUE
191970H745344416161968H7453605461924X3914365
201971H745349117171969H7453721711917X3914213
211972H745324418181970H7453444721918X3914248
221973H745356819191971H7453491731919X3914171
231974H745333120201972H7453244741920X3914388
241975H745323621211973H7453568751921X3914196
251976H745362322221974H7453331761922X3914643
261977H745361423231975H7453236771923X3914565TRUE
271978H745323924241976H7453623781924X3914365
281979H745329125251977H74536141031917X3914213
292031E373645726261978H74532391041918X3914248
302032E3736351TRUE27271979H74532911051919X3914171
312033E373630528282031E37364571061920X3914388
322124L6272683TRUE29292032E3736351TRUE1071921X3914196
332125L627239530302033E37363051081922X3914643
3431312124L6272683TRUE1091923X3914565TRUE
3532322125L62723951101924X3914365
363311761Q70913521351917X3914213
373421762Q70915341361918X3914248
383531763Q70915651371919X3914171
393641764Q7091631TRUE1381920X3914388
403751765Q70915021391921X3914196
413861766Q70912191401922X3914643
423971917X39142131411923X3914565TRUE
434081918X39142481421924X3914365
444191919X39141711671917X3914213
4542101920X39143881681918X3914248
4643111921X39141961691919X3914171
4744121922X39146431701920X3914388
4845131923X3914565TRUE1711921X3914196
4946141924X39143651721922X3914643
5047151967H7453708TRUE1731923X3914565TRUE
Sheet1
Cell Formulas
RangeFormula
F2F2=FORMULATEXT(F4)
G3,I3,O3,N11,X3,R3G3=FORMULATEXT(G4)
F4:F100003F4=SEQUENCE(100000)
G4:G100003G4=MOD(F4#-1,ROWS(A2:D33))+1
I4:L100003I4=INDEX(IF(A2:D33="","",A2:D33),G4#,SEQUENCE(,4))
O4:P8O4=IDIXFLT(I4#)
R4:V25003R4=IDIXFLT(I4#,5)
X4X4=ROWS(R4#)
N12N12=ROWS(I4#)
Dynamic array formulas.
 
Inspired by latest Mr.Excel YT (14-Apr-2022): Count Number Of Weekdays Per Month using Excel - 2481
Task: "Ronak asks: How can I use Excel to find out how many weekdays per month for the whole year?"
2 simple lambdas to solve it using MAKEARRAY , main core function used to reproduce PT functionality in general.
DNY( y ) Day Names/Year y: year 4 digits
Excel Formula:
=LAMBDA(y,
    LET(
        f, DATE(y, 1, 1),
        l, DATE(y, 12, 31),
        s, SEQUENCE(l - f + 1, , f),
        MAKEARRAY(12, 7, LAMBDA(r, c, SUM((c = WEEKDAY(s, 1)) * (r = MONTH(s)))))
    )
)
PTDNY( y ) Pivot Table Day Names/Year, calls DNY( y )
Excel Formula:
=LAMBDA(y,
    LET(
        g, "GT",
        a, DNY(y),
        VSTACK(
            HSTACK(y, TEXT(SEQUENCE(, 7), "ddd"), g),
            HSTACK(TEXT(SEQUENCE(12, , , 31), "mmm"), a, BYROW(a, LAMBDA(x, SUM(x)))),
            HSTACK(g, BYCOL(a, LAMBDA(x, SUM(x))), SUM(a))
        )
    )
)
Book1
ABCDEFGHIJKLMNOPQRS
1
2inner array calculationentire PT
3y,2021
4y,2021=PTDNY(2021)
5=DNY(2021)2021SunMonTueWedThuFriSatGT
65444455Jan544445531
74444444Feb444444428
84555444Mar455544431
94444554Apr444455430
105544445May554444531
114455444Jun445544430
124444555Jul444455531
135554444Aug555444431
144445544Sep444554430
155444455Oct544445531
164554444Nov455444430
174445554Dec444555431
18GT52525252525352365
19
20y,2020 (2020 was a leap year)
21y,2020=PTDNY(2020)
22=DNY(2020)2020SunMonTueWedThuFriSatGT
234445554Jan444555431
244444445Feb444444529
255554444Mar555444431
264445544Apr444554430
275444455May544445531
284554444Jun455444430
294445554Jul444555431
305544445Aug554444531
314455444Sep445544430
324444555Oct444455531
335544444Nov554444430
344455544Dec445554431
35GT52525253535252366
36
37y,2022
38=PTDNY(2022)
392022SunMonTueWedThuFriSatGT
40Jan554444531
41Feb444444428
42Mar445554431
43Apr444445530
44May555444431
45Jun444554430
46Jul544445531
47Aug455544431
48Sep444455430
49Oct554444531
50Nov445544430
51Dec444455531
52GT52525252525253365
53
DNY
Cell Formulas
RangeFormula
J4,J38,B22,J21,B5J4=FORMULATEXT(J5)
J5:R18J5=PTDNY(2021)
B6:H17B6=DNY(2021)
J22:R35J22=PTDNY(2020)
B23:H34B23=DNY(2020)
J39:R52J39=PTDNY(2022)
Dynamic array formulas.
 
If we need to change 1st weekday from Sun to Mon, 2 minor changes (in bold)
DNY( y ): .....SUM((c=WEEKDAY(s,2))*(r=MONTH(s)))))))
Excel Formula:
=LAMBDA(y,
    LET(
        f, DATE(y, 1, 1),
        l, DATE(y, 12, 31),
        s, SEQUENCE(l - f + 1, , f),
        MAKEARRAY(12, 7, LAMBDA(r, c, SUM((c = WEEKDAY(s, 2)) * (r = MONTH(s)))))
    )
)
PTDNY( y ): ....TEXT(SEQUENCE(,7)+1,"ddd").....
Excel Formula:
=LAMBDA(y,
    LET(
        g, "GT",
        a, DNY(y),
        VSTACK(
            HSTACK(y, TEXT(SEQUENCE(, 7) + 1, "ddd"), g),
            HSTACK(TEXT(SEQUENCE(12, , , 31), "mmm"), a, BYROW(a, LAMBDA(x, SUM(x)))),
            HSTACK(g, BYCOL(a, LAMBDA(x, SUM(x))), SUM(a))
        )
    )
)
Book1
ABCDEFGHIJKLMNOPQRSTUV
1
2weekdays or day names sequenceinner array calculationentire PT
31st day Suny,2021
4=TEXT(SEQUENCE(7),"ddd")y,2021=PTDNY(2021)
5Sun=DNY(2021)2021MonTueWedThuFriSatSunGT
6Mon4444555Jan444455531
7Tue4444444Feb444444428
8Wed5554444Mar555444431
9Thu4445544Apr444554430
10Fri5444455May544445531
11Sat4554444Jun455444430
124445554Jul444555431
131st day Mon5544445Aug554444531
14=TEXT(SEQUENCE(7)+1,"ddd")4455444Sep445544430
15Mon4444555Oct444455531
16Tue5544444Nov554444430
17Wed4455544Dec445554431
18ThuGT52525252535252365
19Fri
20Saty,2020 (2020 was a leap year)
21Suny,2020=PTDNY(2020)
22=DNY(2020)2020MonTueWedThuFriSatSunGT
23month sequence4455544Jan445554431
24=TEXT(SEQUENCE(12,,,31),"mmm")4444454Feb444445429
25Jan5544445Mar554444531
26Feb4455444Apr445544430
27Mar4444555May444455531
28Apr5544444Jun554444430
29May4455544Jul445554431
30Jun5444455Aug544445531
31Jul4554444Sep455444430
32Aug4445554Oct444555431
33Sep5444445Nov544444530
34Oct4555444Dec455544431
35NovGT52525353525252366
36Dec
37y,2022
38=PTDNY(2022)
392022MonTueWedThuFriSatSunGT
40Jan544445531
41Feb444444428
42Mar455544431
43Apr444455430
44May554444531
45Jun445544430
46Jul444455531
47Aug555444431
48Sep444554430
49Oct544445531
50Nov455444430
51Dec444555431
52GT52525252525352365
53
DNY 2
Cell Formulas
RangeFormula
B4,M38,B24,E22,M21,B14,E5,M4B4=FORMULATEXT(B5)
B5:B11B5=TEXT(SEQUENCE(7),"ddd")
M5:U18M5=PTDNY(2021)
E6:K17E6=DNY(2021)
B15:B21B15=TEXT(SEQUENCE(7)+1,"ddd")
M22:U35M22=PTDNY(2020)
E23:K34E23=DNY(2020)
B25:B36B25=TEXT(SEQUENCE(12,,,31),"mmm")
M39:U52M39=PTDNY(2022)
Dynamic array formulas.
 
On the comments section Laza Lazarevic asked a good question:
"How to exclude the holidays?"
These are the new functions that take holidays into consideration:
EHDNY(y,[h]) Exclude Holidays Day Names/Year (y: year ; [h]: holidays array)
Excel Formula:
=LAMBDA(y, [h],
    LET(
        f, DATE(y, 1, 1),
        l, DATE(y, 12, 31),
        d, SEQUENCE(l - f + 1, , f),
        s, IF(ISOMITTED(h), d, FILTER(d, NOT(IFNA(XMATCH(d, h), 0)))),
        MAKEARRAY(12, 7, LAMBDA(r, c, SUM((c = WEEKDAY(s, 2)) * (r = MONTH(s)))))
    )
)
PTEHDNY(y,[h]) (we only must add the extra argument "h" and replace DNY( y ) in the formula with EHDNY(y,h) )
Excel Formula:
=LAMBDA(y, [h],
    LET(
        g, "GT",
        a, EHDNY(y, h),
        VSTACK(
            HSTACK(y, TEXT(SEQUENCE(, 7) + 1, "ddd"), g),
            HSTACK(TEXT(SEQUENCE(12, , , 31), "mmm"), a, BYROW(a, LAMBDA(x, SUM(x)))),
            HSTACK(g, BYCOL(a, LAMBDA(x, SUM(x))), SUM(a))
        )
    )
)
Book1
ABCDEFGHIJ
1Exclude holidays.EHDNY(y,[h]) function concept.
2
3sample date arrayholydays array
4=SEQUENCE(31,,"1-1-22")=IFNA(XMATCH(B5#,D5:D12),0)=FILTER(B5#,NOT(F5#))
501-01-2214-01-22001-01-22
602-01-2215-01-22002-01-22
703-01-2216-01-22003-01-22
804-01-2217-01-22004-01-22
905-01-2218-01-22005-01-22
1006-01-2219-01-22006-01-22
1107-01-2229-01-22007-01-22
1208-01-2231-01-22008-01-22
1309-01-22009-01-22
1410-01-22010-01-22
1511-01-22011-01-22
1612-01-22012-01-22
1713-01-22013-01-22
1814-01-22120-01-22
1915-01-22221-01-22
2016-01-22322-01-22
2117-01-22423-01-22
2218-01-22524-01-22
2319-01-22625-01-22
2420-01-22026-01-22
2521-01-22027-01-22
2622-01-22028-01-22
2723-01-22030-01-22
2824-01-220
2925-01-220
3026-01-220
3127-01-220
3228-01-220
3329-01-227
3430-01-220
3531-01-228
36
DNY 4
Cell Formulas
RangeFormula
B4,F4,H4B4=FORMULATEXT(B5)
B5:B35B5=SEQUENCE(31,,"1-1-22")
F5:F35F5=IFNA(XMATCH(B5#,D5:D12),0)
H5:H27H5=FILTER(B5#,NOT(F5#))
Dynamic array formulas.
 
Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAAB
12021-2022y,2021,h,omittedy,2021,h,B3:B40
2holydays array=PTEHDNY(2021)=PTEHDNY(2021,B3:B40)check results
301-01-212021MonTueWedThuFriSatSunGT2021MonTueWedThuFriSatSunGTnr. holydays 2021
402-01-21Jan444455531Jan444444428=ROWS(FILTER(B3:B40,YEAR(B3:B40)=2021))
503-01-21Feb444444428Feb44444442819
615-08-21Mar555444431Mar555444431=L16-V16
716-08-21Apr444554430Apr44455443019
817-08-21May544445531May544445531
918-08-21Jun455444430Jun455444430
1019-08-21Jul444555431Jul444555431
1120-08-21Aug554444531Aug443333323
1221-08-21Sep445544430Sep445544430
1322-08-21Oct444455531Oct444455531
1424-12-21Nov554444430Nov554444430
1525-12-21Dec445554431Dec334433323
1626-12-21GT52525252535252365GT50505050494948346
1727-12-21
1828-12-21y,2022,h,omittedy,2022,h,B3:B40
1929-12-21=PTEHDNY(2022)=PTEHDNY(2022,B3:B40)check results
2030-12-212022MonTueWedThuFriSatSunGT2022MonTueWedThuFriSatSunGTnr. holydays 2022
2131-12-21Jan544445531Jan444444428=ROWS(FILTER(B3:B40,YEAR(B3:B40)=2022))
2201-01-22Feb444444428Feb44444442819
2302-01-22Mar455544431Mar455544431=L33-V33
2403-01-22Apr444455430Apr44445543019
2515-08-22May554444531May554444531
2616-08-22Jun445544430Jun445544430
2717-08-22Jul444455531Jul444455531
2818-08-22Aug555444431Aug344333323
2919-08-22Sep444554430Sep444554430
3020-08-22Oct544445531Oct544445531
3121-08-22Nov455444430Nov455444430
3222-08-22Dec444555431Dec333443323
3324-12-22GT52525252525352365GT48505050504949346
3425-12-22
DNY 5
Cell Formulas
RangeFormula
D2,X23,X21,N19,D19,X6,X4,N2D2=FORMULATEXT(D3)
D3:L16D3=PTEHDNY(2021)
N3:V16N3=PTEHDNY(2021,B3:B40)
X5X5=ROWS(FILTER(B3:B40,YEAR(B3:B40)=2021))
X7,X24X7=L16-V16
D20:L33D20=PTEHDNY(2022)
N20:V33N20=PTEHDNY(2022,B3:B40)
X22X22=ROWS(FILTER(B3:B40,YEAR(B3:B40)=2022))
Dynamic array formulas.
 
What if we have an array of dates (more years) and we want to extract the distribution of weekdays for each month (all years together) ?
Concept:

Book1
ABCDEFGHIJKLMNOP
1random dates btw 1-1-21,31-12-22 300 rowswkdy distribution entire array
2=RANDARRAY(300,,"1-1-21","31-12-22",1)=HSTACK(TEXT(SEQUENCE(7),"ddd"),DROP(FREQUENCY(D5#,SEQUENCE(7)),-1))
3↓↓↓wkdys entire array↓↓↓wkdy distribution only Jan
4↓↓↓=WEEKDAY(B5#)↓↓↓=FILTER(B5#,MONTH(B5#)=1)
511-09-221↓↓↓↓↓↓=DROP(FREQUENCY(WEEKDAY(I6#),SEQUENCE(7)),-1)
622-10-227Sun4321-01-227
723-07-227Mon3831-01-211
810-08-224Tue4427-01-212
922-12-214Wed4923-01-213
1018-07-222Thu3826-01-215
1111-04-211Fri3712-01-223
1220-08-216Sat5121-01-227
1313-06-21104-01-21
1411-09-22103-01-21
1512-11-21614-01-22
1613-09-21214-01-21
1703-08-22409-01-21
1820-11-21716-01-21
1918-04-22220-01-22
2008-04-22613-01-22
2104-08-21414-01-21
2211-03-21502-01-22
2320-03-21723-01-22
2420-08-21601-01-22
2505-12-21126-01-22
2609-08-22325-01-22
2721-01-22627-01-22
2805-06-21722-01-22
2924-07-21708-01-22
3017-06-215down to 300 rows16-01-22
3103-03-214↓↓↓↓↓↓↓↓↓15-01-22
3223-10-21709-01-22
3322-03-22310-01-21
3409-04-227
Sheet7
Cell Formulas
RangeFormula
B2B2=FORMULATEXT(B5)
F2F2=FORMULATEXT(F6)
D4,K5D4=FORMULATEXT(D5)
I4I4=FORMULATEXT(I6)
B5:B304B5=RANDARRAY(300,,"1-1-21","31-12-22",1)
D5:D304D5=WEEKDAY(B5#)
F6:G12F6=HSTACK(TEXT(SEQUENCE(7),"ddd"),DROP(FREQUENCY(D5#,SEQUENCE(7)),-1))
I6:I33I6=FILTER(B5#,MONTH(B5#)=1)
K6:K12K6=DROP(FREQUENCY(WEEKDAY(I6#),SEQUENCE(7)),-1)
Dynamic array formulas.
 
We have seen how we can calculate the distribution of weekdays for 1 month.
So we can use the custom-made lambda helper function that can spill byrow, SPILLBYROW (this thread post#50), a function that can spill rows even if source array is 1D, this format:
SPILLBYROW(SEQUENCE(12),LAMBDA(i,fn(i)))
Here are 2 methods, 2 simple lambda formulas, 2 different ways to solve the inner array (distribution values w/o the rest of other PT elements)
Book1
ABCDEFGHIJKLMNOPQR
1random dates btw 1-1-21,31-12-22 300 rows
2=RANDARRAY(300,,"1-1-21","31-12-22",1)
3↓↓↓
4↓↓↓SunMonTueWedThuFriSat
507-09-221st method
602-11-22=SPILLBYROW(SEQUENCE(12),LAMBDA(i,TOROW(DROP(FREQUENCY(WEEKDAY(FILTER(B5#,MONTH(B5#)=i)),SEQUENCE(7)),-1))))
708-02-216335185Jan
829-07-226353223Feb
906-11-212244121Mar
1026-06-213335413Apr
1131-05-216545231May
1217-05-214144634Jun
1320-06-225453653Jul
1426-07-212454332Aug
1514-10-222366455Sep
1602-06-212381344Oct
1726-11-212435435Nov
1802-01-215351221Dec
1931-08-21
2018-10-212nd method
2104-07-21=SPILLBYROW(SEQUENCE(12),LAMBDA(i,BYCOL((MONTH(B5#)=i)*(WEEKDAY(B5#)=SEQUENCE(,7)),LAMBDA(x,SUM(x)))))
2208-05-226335185Jan
2323-03-226353223Feb
2412-05-222244121Mar
2512-12-223335413Apr
2626-09-216545231May
2708-09-224144634Jun
2807-10-215453653Jul
2907-01-222454332Aug
3023-07-212366455Sep
3129-07-212381344Oct
3224-12-222435435Nov
3301-08-225351221Dec
3402-01-22
3527-09-22
3618-02-21checking 1st method
3703-02-21=BYCOL(D7#,LAMBDA(x,SUM(x)))
3829-06-2145385546384137
3918-05-22
4014-07-21checking 2nd method
4106-01-21=BYCOL(D22#,LAMBDA(x,SUM(x)))
4206-02-2145385546384137
4313-07-22
4429-03-21cheking wkdy distribution entire array
4501-10-22=HSTACK(TEXT(SEQUENCE(7),"ddd"),DROP(FREQUENCY(WEEKDAY(B5#),SEQUENCE(7)),-1))
4622-09-21Sun45
4708-01-22Mon38
4830-11-21Tue55
4917-01-21Wed46
5003-11-21Thu38
5106-12-22Fri41
5222-05-22Sat37
5302-01-22
5405-10-21
5502-12-22down to 300 rows
5611-06-22↓↓↓↓↓↓↓↓↓
5731-10-22
Sheet7
Cell Formulas
RangeFormula
B2B2=FORMULATEXT(B5)
D4:J4D4=TEXT(SEQUENCE(,7),"ddd")
B5:B304B5=RANDARRAY(300,,"1-1-21","31-12-22",1)
D6,D45,D41,D37,D21D6=FORMULATEXT(D7)
D7:J18D7=SPILLBYROW(SEQUENCE(12),LAMBDA(i,TOROW(DROP(FREQUENCY(WEEKDAY(FILTER(B5#,MONTH(B5#)=i)),SEQUENCE(7)),-1))))
D22:J33D22=SPILLBYROW(SEQUENCE(12),LAMBDA(i,BYCOL((MONTH(B5#)=i)*(WEEKDAY(B5#)=SEQUENCE(,7)),LAMBDA(x,SUM(x)))))
D38:J38D38=BYCOL(D7#,LAMBDA(x,SUM(x)))
D42:J42D42=BYCOL(D22#,LAMBDA(x,SUM(x)))
D46:E52D46=HSTACK(TEXT(SEQUENCE(7),"ddd"),DROP(FREQUENCY(WEEKDAY(B5#),SEQUENCE(7)),-1))
Dynamic array formulas.
 
Task: Using a lambda formula (SPILLBYROW versatility) extract all weekdays dates from an array of dates.
Nr weekdays 2481.xlsx
ABCDEFGHIJKLMNO
1random dates btw 1-1-21,31-12-22 50 rows
2=RANDARRAY(50,,"1-1-21","31-12-22",1)
3↓↓↓
4↓↓↓=LET(a,B5#,s,SEQUENCE(7),HSTACK(TEXT(s,"ddd"),SPILLBYROW(s,LAMBDA(i,TOROW(SORT(FILTER(a,WEEKDAY(a)=i)))))))
520-03-21Sun13-06-2101-08-2123-01-2231-07-2225-09-2225-12-22
623-04-21Mon10-05-2104-04-2211-07-2208-08-2212-09-22
727-07-21Tue27-07-2107-12-2130-08-2227-09-22
807-12-21Wed13-01-2105-05-2107-07-2113-10-2102-03-2204-05-2224-08-2214-09-2214-09-2230-11-22
927-09-22Thu18-03-2122-04-2106-05-2125-11-2102-12-2113-01-2210-02-2209-06-2229-12-22
1001-01-22Fri19-03-2123-04-2101-10-2129-04-2220-05-2210-06-2229-07-22
1120-05-22Sat02-01-2120-03-2104-09-2118-09-2125-12-2101-01-2222-01-2222-10-2205-11-22
1205-11-22
1319-03-21check
1430-08-22=IFERROR(WEEKDAY(DROP(D5#,,1)),"")
1531-07-22111111
1609-06-2222222
1725-12-213333
1808-08-224444444444
1901-10-21555555555
2022-01-226666666
2125-12-22777777777
2229-12-22
2322-10-22
2412-09-22
2513-01-21
2623-01-22
2704-04-22
2829-07-22
2910-02-22
3010-05-21
3124-08-22
3213-06-21
3304-09-21
3410-06-22
3511-07-22
3614-09-22
3725-11-21
3818-09-21
3929-04-22
4001-08-21
4102-03-22
4214-09-22
4313-10-21
4405-05-21
4504-05-22
4602-12-21
4707-07-21
4806-05-21
4922-04-21
5025-09-22
5102-01-21
5213-01-22
5318-03-21
5430-11-22
55
DNY 7
Cell Formulas
RangeFormula
B2B2=FORMULATEXT(B5)
D4,E14D4=FORMULATEXT(D5)
B5:B54B5=RANDARRAY(50,,"1-1-21","31-12-22",1)
D5:N11D5=LET(a,B5#,s,SEQUENCE(7),HSTACK(TEXT(s,"ddd"),SPILLBYROW(s,LAMBDA(i,TOROW(SORT(FILTER(a,WEEKDAY(a)=i)))))))
E15:N21E15=IFERROR(WEEKDAY(DROP(D5#,,1)),"")
Dynamic array formulas.
 
Forgot to add UNIQUE, in case dates array has dups.
.....SPILLBYROW(s,LAMBDA(i,TOROW(SORT(UNIQUE(FILTER(a,WEEKDAY(a)=i))))))))
Nr weekdays 2481.xlsx
ABCDEFGHIJKLMNOPQ
1random dates btw 1-1-21,31-12-22 50 rows
2=RANDARRAY(50,,"1-1-21","31-12-22",1)
3↓↓↓
4↓↓↓=LET(a,B5#,s,SEQUENCE(7),HSTACK(TEXT(s,"ddd"),SPILLBYROW(s,LAMBDA(i,TOROW(SORT(UNIQUE(FILTER(a,WEEKDAY(a)=i))))))))
518-04-22Sun11-04-2124-10-2109-01-2213-03-2226-06-2204-12-22
611-04-21Mon05-07-2119-07-2129-11-2127-12-2103-01-2211-04-2218-04-2219-09-22
707-01-21Tue26-01-2106-07-2119-10-2107-12-2108-02-2218-10-2229-11-22
801-09-22Wed10-02-2110-03-2102-06-2122-09-2108-12-2102-02-2216-02-2209-03-2218-05-2203-08-22
903-06-21Thu07-01-2125-02-2103-06-2111-11-2103-02-2224-02-2207-04-2223-06-2201-09-2229-09-22
1003-09-22Fri15-01-2121-01-2201-07-22
1103-02-22Sat04-06-2203-09-2222-10-2210-12-2231-12-22
1229-11-21
1321-01-22check
1408-12-21=IFERROR(WEEKDAY(DROP(D5#,,1)),"")
1526-06-22111111
1610-12-2222222222
1729-11-223333333
1803-08-224444444444
1919-09-225555555555
2008-02-22666
2118-05-2277777
2213-03-22
2304-06-22
2402-06-21
2527-12-21
2605-07-21
2723-06-22
2825-02-21
2922-09-21
3024-10-21
3106-07-21
3201-07-22
3319-07-21
3418-10-22
3509-01-22
3610-02-21
3729-09-22
3826-01-21
3909-03-22
4025-02-21
4115-01-21
4203-01-22
4310-03-21
4416-02-22
4522-10-22
4604-12-22
4711-04-22
4824-02-22
4907-12-21
5011-11-21
5102-02-22
5207-04-22
5331-12-22
5419-10-21
55
DNY 7
Cell Formulas
RangeFormula
B2B2=FORMULATEXT(B5)
D4,E14D4=FORMULATEXT(D5)
B5:B54B5=RANDARRAY(50,,"1-1-21","31-12-22",1)
D5:N11D5=LET(a,B5#,s,SEQUENCE(7),HSTACK(TEXT(s,"ddd"),SPILLBYROW(s,LAMBDA(i,TOROW(SORT(UNIQUE(FILTER(a,WEEKDAY(a)=i))))))))
E15:N21E15=IFERROR(WEEKDAY(DROP(D5#,,1)),"")
Dynamic array formulas.
 

Forum statistics

Threads
1,223,947
Messages
6,175,560
Members
452,652
Latest member
eduedu

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