Forum Discussion
Vinnie_Smith
Apr 14, 2024Copper Contributor
4 integera (with no separators) in each cell of a column range. Counting each individual interger
Hello- Help! I have a column that I have manually entered (or copied in) 4 digit numbers. All cell entries are exactly four digits, 0-9, with duplicates allowed (ex. 4424). I need a formula that ...
Patrick2788
Apr 14, 2024Silver Contributor
With 365 you can do this a few different ways.
This method 'explodes' each 4 digit number by converting each to a 1x4 array. The result of using explode on the entire column is a matrix of numbers 4 columns wide. TOCOL converts this matrix to a vector and then REDUCE cleans up.
=LET(
explode, LAMBDA(integer, MID(integer, {1, 2, 3, 4}, 1)),
number_vector, TOCOL(explode(numbers)),
unique_numbers, SORT(UNIQUE(number_vector)),
CountNumbers, LAMBDA(acc, i,
LET(
total, SUM(N(i = number_vector)),
VSTACK(acc, HSTACK(i, total))
)
),
REDUCE({"Totals", "Count"}, unique_numbers, CountNumbers)
)
This task becomes a bit easier with access to the Insider function GROUPBY:
=LET(
explode, LAMBDA(integer, MID(integer, {1, 2, 3, 4}, 1)),
number_vector, TOCOL(explode(numbers)),
GROUPBY(number_vector, number_vector, COUNTA)
)