Forum Discussion
Joh_Loh
Apr 24, 2024Copper Contributor
How to create an autonumbering formula based on three columns
Update: Black cat on Stack Overflow gave the following formula that worked great: =MATCH(A2,UNIQUE(A$2:A2),0)&"."&MATCH(B2,UNIQUE(FILTER(B$2:B2,A2=A$2:A2)),0)&"."&MATCH(C2,UNIQUE(FILTER($C$2:$C2,A$...
PeterBartholomew1
Apr 25, 2024Silver Contributor
Seems I made too much of a meal of this! As well as generating a code that depends upon the sorted order as opposed to the original order.
This is mainly sorting and formatting
= LET(
seq, SEQUENCE(13),
sorted, SORT(HSTACK(spec,seq), {1,2,3}),
autoNum, SCAN(0, SEQUENCE(13), IncrementAutoNumλ),
formatted, TEXT(autoNum, "0\,0\,0"),
SORTBY(formatted, CHOOSECOLS(sorted, 4))
)
The key is the Lambda function that identifies model changes and increments the code
IncrementAutoNumλ
= LAMBDA(acc,k,
IF(k=1,
111,
LET(
changeMake?, COUNTA(UNIQUE(INDEX(sorted, VSTACK(k, k-1), 1))) - 1,
changeModel?, COUNTA(UNIQUE(INDEX(sorted, VSTACK(k, k-1), 2))) - 1,
increment, IFS(changeMake?, 100, changeModel?, 10, 1, 1),
acc + increment
)
)
)
Now I guess its time to look at the other solutions to determine how to get the result efficiently!