This question is about how the Excel COUNTIF function processes different data types when used as an array formula.
There are many good posts detailing the use of COUNTIF for tasks such as extracting unique values ββfrom a list, such as this post . I managed to use examples from this and other posts to solve specific problems, but I am trying to get a deeper understanding of array formulas in order to adapt my formulas to new needs.
I came across a peculiar COUNTIF behavior. In general, Excel seems to treat strings as "greater than" numbers, so the following examples are true:
Cell Formula Returns =1<2 TRUE ="a"<"b" TRUE ="a">"b" FALSE =1<"b" TRUE
Now suppose the range A1: A6 contains the following data set:
1 2 3 A B C
For each cell of this set, I want to check how many of all the cells in the set are less than or equal to this cell (a useful method in more complex formulas). I introduce the following array formula in the range B1: B6:
{=COUNTIF($A$1:$A$6,"<="&$A$1:$A$6)} (CTRL + SHIFT + ENTER)
According to the examples of comparing numbers and strings above (also shown in column D below), I expect the result shown below to look like column C. However, the array formula returns the result shown in column B, which assumes the rows and numeric elements are counted separately using the COUNTIF array.
Column A Column B Column C Column D 1 1 1 A1<"C" = TRUE 2 2 2 A2<"C" = TRUE 3 3 3 A3<"C" = TRUE A 1 4 A4<"C" = TRUE B 2 5 A5<"C" = TRUE C 3 6 A6<"C" = FALSE
So, the question is how to output in column C? ( EDIT: To clarify, I'm specifically looking for solutions that use the properties of the COUNTIF array.)
Any insight into why a massive COUNTIF appears to behave differently than single-cell examples is also much appreciated.
NOTE. I have translated examples from a non-English version of Excel, so I apologize in advance for any typos.
PS. For the background, I ran into this problem when I tried to build a formula that would extract unique values ββfrom a list with possible duplicates and sort the unique values ββin numerical / alphabetical order. My real solution is to do this in two steps. Here one solution is proposed, how to do it in one step .