I have a column A
that looks like:
11
11 11
5 6
5 5
5 6 6 5
11 11 11 11
6 7 8
3
3 2 3
and seeking for an alternative-smarter way how to output TRUE
/FALSE
as shown here:
desired result | |
---|---|
11 | TRUE |
FALSE | |
11 11 | TRUE |
5 6 | FALSE |
5 5 | TRUE |
5 6 6 5 | TRUE |
11 11 11 11 | TRUE |
FALSE | |
6 7 8 | FALSE |
3 | TRUE |
3 2 3 | TRUE |
The logic is:
FALSE
if
TRUE
if
More notes:
How can I solve it:
I can sum it (in various ways - LAMBDA
, QUERY(SUBSTITUTE(
, SUM(SPLIT(
, ...) and devide it by count. if result is whole number its TRUE
, if result has decimal places its FALSE
but this wont work for 3 2 3
, 6 7 8
.
Another way would be to split it and use QUERY
and count numbers per row, group by row_numbers and pivot by all_numbers, via LET
then wrap it into IF
and remove numbers lower than 2
. Next smash it with TRIM(TOCOL(QUERY(TRANSPOSE(
and LEN
it. Then IF
it like >0
is TRUE
and add rest of the logic for cases not covered by the QUERY
.
Formula would be enormous in either way, so I'm looking for some "smarter/shorter" way (if any). Maybe there is some magic regex patern I am not familiar with?
Assuming the data is in A2:A
, You can use the following formula in B2
and drag it down.
=ARRAYFORMULA(LET(s,IFERROR(SPLIT(A2," ")),OR(COUNTA(s)=1,COUNTIF(s,s)>1)))
Or with a single formula in B2
:
=ARRAYFORMULA(
BYROW(
IFERROR(SPLIT(A2:INDEX(A:A,MATCH(,0/LEN(A:A)))," ")),
LAMBDA(s,OR(COUNTA(s)=1,COUNTIF(s,s)>1))
)
)
First, we split the string by the space and assign the result to s
s ← IFERROR(SPLIT(A2," "))
Then we use the OR function
to return TRUE
if the splitted string has only one value or has at least one value that occurs more than once
OR(COUNTA(s)=1,COUNTIF(s,s)>1)