Xlambda
Well-known Member
- Joined
- Mar 8, 2021
- Messages
- 837
- Office Version
- 365
- Platform
- Windows
AFILL replaces all blanks/null strings of an array/array area, with other array values. !! NEW !! MAKEARRAY , SCAN . Calls AFLAT.
Exactly same functionality like in APUZZLE, only this time, only blanks/null strings will be replaced. If we want to change the condition variable, (cd,a="") , it's the first one after LET.
Exactly same functionality like in APUZZLE, only this time, only blanks/null strings will be replaced. If we want to change the condition variable, (cd,a="") , it's the first one after LET.
Excel Formula:
=LAMBDA(a,b,[r1w],[r2w],[c1l],[c2l],
LET(cd,a="",fb,AFLAT(b,1),r,ROWS(a),c,COLUMNS(a),x,MEDIAN(1,IF(r1w,r1w,1),r),y,MEDIAN(1,IF(r2w,r2w,r),r),z,MEDIAN(1,IF(c1l,c1l,1),c),w,MEDIAN(1,IF(c2l,c2l,c),c),
m,cd*MAKEARRAY(r,c,LAMBDA(r,c,IF(x>y,(r>=x)+(r<=y),(r>=x)*(r<=y))*IF(z>w,(c>=z)+(c<=w),(c>=z)*(c<=w)))),
s,IFERROR(INDEX(fb,SCAN(0,m,LAMBDA(v,a,v+a))),""),
IF(m,s,IF(a="","",a))
)
)
LAMBDA 1.1.1.xlsx | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | |||
1 | Absolute: Every time we needed to write single cell formulas dynamic reports, to look like PT/PQ reports, more than 1/3 of formula length is allocated to build those "puzzles" of appending headers, full columns, grand total rows and columns, corners etc. All this set of functions APP2H, APP2V with offset capabilities, APUZZLE, AFILL , will make this constructions a breeze. | |||||||||||||||||||||||||
2 | AFILL replaces all blanks/null strings of an array/array area, with other array values | blanks/null strings | ||||||||||||||||||||||||
3 | r1w,r2w,c1l,c2l arguments, same functionality as in APUZZLE function, selects area or areas of an array. Data outside area selected will remain unchanged. | |||||||||||||||||||||||||
4 | If all arguments are omitted, all blanks of "a" will be filled with second array "b" values from left to right, top to bottom. | |||||||||||||||||||||||||
5 | Because only blanks will be replaced we do not need to be as precise with the area selections, like in APUZZLE functions that replaces all the area values | |||||||||||||||||||||||||
6 | a | b | ||||||||||||||||||||||||
7 | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | A | B | |||||||||||||||
8 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | C | D | ||||||||||||||||
9 | 21 | 22 | 23 | 24 | 26 | 27 | 30 | #N/A | E | F | ||||||||||||||||
10 | 31 | 34 | 35 | 37 | 38 | 39 | 40 | G | H | I | ||||||||||||||||
11 | ||||||||||||||||||||||||||
12 | all arg.omitted | if we want to exclude blanks of "b" array, we use as "b" arg. AFLAT(b) | ||||||||||||||||||||||||
13 | =AFILL(B7:K10,M7:O10) | =AFILL(B7:K10,AFLAT(M7:O10)) | ||||||||||||||||||||||||
14 | 1 | 2 | 3 | 4 | 5 | 6 | A | 8 | 9 | 10 | 1 | 2 | 3 | 4 | 5 | 6 | A | 8 | 9 | 10 | ||||||
15 | 11 | B | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 11 | B | C | 14 | 15 | 16 | 17 | 18 | 19 | 20 | |||||||
16 | 21 | 22 | 23 | 24 | C | 26 | 27 | D | 30 | 21 | 22 | 23 | 24 | D | 26 | 27 | E | F | 30 | |||||||
17 | 31 | E | 34 | 35 | F | 37 | 38 | 39 | 40 | 31 | G | H | 34 | 35 | I | 37 | 38 | 39 | 40 | |||||||
18 | ||||||||||||||||||||||||||
19 | Note: unlike APUZZLE (that replaces whole selected areas ),with AFILL we can select bigger areas, since only blanks will be replaced | |||||||||||||||||||||||||
20 | ||||||||||||||||||||||||||
21 | ,,8,4 | ,3 (col arguments omitted , all columns will be selected) | ||||||||||||||||||||||||
22 | =AFILL(B7:K10,M7:O10,,,8,4) | =AFILL(B7:K10,M7:O10,,3) | ||||||||||||||||||||||||
23 | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 1 | 2 | 3 | 4 | 5 | 6 | A | 8 | 9 | 10 | |||||||
24 | 11 | A | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 11 | B | 14 | 15 | 16 | 17 | 18 | 19 | 20 | ||||||||
25 | 21 | 22 | 23 | 24 | 26 | 27 | B | C | 30 | ↑ | 21 | 22 | 23 | 24 | C | 26 | 27 | D | 30 | |||||||
26 | 31 | D | 34 | 35 | 37 | 38 | 39 | 40 | <=3 | 31 | 34 | 35 | 37 | 38 | 39 | 40 | ||||||||||
27 | ← | <=4 | >=8 | → | ||||||||||||||||||||||
28 | "puzzle functionality" | |||||||||||||||||||||||||
29 | a | b | =AFILL(B30:E34,G30:H32) | |||||||||||||||||||||||
30 | 1 | 2 | 3 | 4 | A | AA | 1 | 2 | 3 | 4 | ||||||||||||||||
31 | 5 | 6 | B | BB | A | 5 | 6 | AA | ||||||||||||||||||
32 | 7 | 8 | C | CC | B | 7 | 8 | BB | ||||||||||||||||||
33 | 9 | 10 | C | 9 | 10 | CC | ||||||||||||||||||||
34 | 11 | 12 | 13 | 14 | 11 | 12 | 13 | 14 | ||||||||||||||||||
35 | Is like appending 3 arrays but filling only the gaps | |||||||||||||||||||||||||
36 | if "gaps" of "a" are offset | |||||||||||||||||||||||||
37 | a | b | =AFILL(B38:E42,G38:H40) | |||||||||||||||||||||||
38 | 1 | 2 | 3 | A | AA | 1 | 2 | 3 | A | |||||||||||||||||
39 | 4 | 5 | B | BB | AA | 4 | 5 | B | ||||||||||||||||||
40 | 6 | 7 | C | CC | BB | 6 | 7 | C | ||||||||||||||||||
41 | 8 | 8 | 10 | CC | 8 | 8 | 10 | |||||||||||||||||||
42 | 11 | 12 | 13 | 14 | 11 | 12 | 13 | 14 | ||||||||||||||||||
43 | not expected outcome, columns are swapped due to the filling pattern, left to right, top to bottom | |||||||||||||||||||||||||
44 | for this situations, nested AFILL | cool trick to solve this in one take, is to swap b columns | ||||||||||||||||||||||||
45 | =AFILL(AFILL(B38:E42,G38:G40,,,,1),H38:H40) | =AFILL(B38:E42,INDEX(G38:H40,SEQUENCE(3),{2,1})) | ||||||||||||||||||||||||
46 | 1 | 2 | 3 | AA | 1 | 2 | 3 | AA | ||||||||||||||||||
47 | A | 4 | 5 | BB | A | 4 | 5 | BB | ||||||||||||||||||
48 | B | 6 | 7 | CC | B | 6 | 7 | CC | ||||||||||||||||||
49 | C | 8 | 8 | 10 | C | 8 | 8 | 10 | ||||||||||||||||||
50 | 11 | 12 | 13 | 14 | 11 | 12 | 13 | 14 | ||||||||||||||||||
51 | ||||||||||||||||||||||||||
52 | funny trick - it's an obvious and flagrant mistake to try to sneak a variable in a constant array, like in {"a","b","c";1,2,x} . | |||||||||||||||||||||||||
53 | Always keeping formulas as short as possible, not over declaring variables, surprised myself several times trying it.? | |||||||||||||||||||||||||
54 | Then, had to use CHOOSE,is ok, but, | Now with AFILL is a breeze, we only have to place | ||||||||||||||||||||||||
55 | we need to put the values one by one ? | null strings where we want variables, and fill them ✌ | ||||||||||||||||||||||||
56 | =LET(x,3,CHOOSE({1,2,3;4,5,6},"a","b","c",1,2,x)) | =LET(x,3,AFILL({"a","b","c";1,2,""},x)) | ||||||||||||||||||||||||
57 | a | b | c | a | b | c | ||||||||||||||||||||
58 | 1 | 2 | 3 | 1 | 2 | 3 | ||||||||||||||||||||
59 | ||||||||||||||||||||||||||
60 | -if we need this several times, for dif variables, writing many CHOOSE becomes a mess, with AFILL we can declare a variable, | |||||||||||||||||||||||||
61 | the constant array with a "gap", and "fill" it with ease as many time as we want, like in this construction | |||||||||||||||||||||||||
62 | =….x,3,y,4,c,{"a","b","c";1,2,""},xf,AFILL(c,x),yf,AFILL(c,y)... | |||||||||||||||||||||||||
63 | ||||||||||||||||||||||||||
AFILL post 1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
H7,O8 | H7 | ="" |
M9 | M9 | =NA() |
B13,B56,J56,J45,B45,J37,J29,N22,B22,M13 | B13 | =FORMULATEXT(B14) |
B14:K17 | B14 | =AFILL(B7:K10,M7:O10) |
M14:V17 | M14 | =AFILL(B7:K10,AFLAT(M7:O10)) |
B23:K26 | B23 | =AFILL(B7:K10,M7:O10,,,8,4) |
N23:W26 | N23 | =AFILL(B7:K10,M7:O10,,3) |
J30:M34,J38:M42 | J30 | =AFILL(B30:E34,G30:H32) |
B46:E50 | B46 | =AFILL(AFILL(B38:E42,G38:G40,,,,1),H38:H40) |
J46:M50 | J46 | =AFILL(B38:E42,INDEX(G38:H40,SEQUENCE(3),{2,1})) |
B57:D58 | B57 | =LET(x,3,CHOOSE({1,2,3;4,5,6},"a","b","c",1,2,x)) |
J57:L58 | J57 | =LET(x,3,AFILL({"a","b","c";1,2,""},x)) |
Dynamic array formulas. |
Upvote
0