Explanation

Although FILTER is more commonly used to filter rows, you can also filter columns, the trick is to supply an array with the same number of columns as the source data. In this example, we construct the array we need with boolean logic , also called Boolean algebra.

In Boolean algebra, multiplication corresponds to AND logic, and addition corresponds to OR logic . In the example shown, we are using Boolean algebra with OR logic (addition) to target only the columns A, C, and E like this:

(B4:G4="a")+(B4:G4="c")+(B4:G4="e")

After each expression is evaluated, we have three arrays of TRUE/FALSE values:

{TRUE,FALSE,FALSE,FALSE,FALSE,FALSE}+
{FALSE,FALSE,TRUE,FALSE,FALSE,FALSE}+
{FALSE,FALSE,FALSE,FALSE,TRUE,FALSE}

The math operation (addition) converts the TRUE and FALSE values to 1s and 0s, so you can think of the operation like this:

{1,0,0,0,0,0}+
{0,0,1,0,0,0}+
{0,0,0,0,1,0}

In the end, we have a single horizontal array of 1s and 0s:

{1,0,1,0,1,0}

which is delivered directly to the FILTER function as the include argument:

=FILTER(B5:G12,{1,0,1,0,1,0})

Notice there are 6 columns in the source data and 6 values in the array, all either 1 or 0. FILTER uses this array as a filter to include only columns 1, 3, and 5 from the source data. Columns 2, 4, and 6 are removed. In other words, the only columns that survive are associated with 1s.

With the MATCH function

Applying OR logic with addition as shown above works fine, but it doesn’t scale well, and makes it impossible to use a range of values from a worksheet as criteria. As an alternative, you can use the MATCH function together with the ISNUMBER function like this to construct the include argument more efficiently:

=FILTER(B5:G12,ISNUMBER(MATCH(B4:G4,{"a","c","e"},0)))

The MATCH function is configured to look for all column headers in the array constant {“a”,“c”,“e”} as shown. We do it this way so that the result from MATCH has dimensions compatible with the source data, which contains 6 columns. Notice also that the third argument in MATCH is set as zero to force an exact match.

After MATCH runs, it returns an array like this:

{1,#N/A,2,#N/A,3,#N/A}

This array goes directly into ISNUMBER, which returns another array:

{TRUE,FALSE,TRUE,FALSE,TRUE,FALSE}

As above, this array is horizontal and contains 6 values separated by commas. FILTER uses the array to remove columns 2, 4, and 6.

With a range

Since the column headers are already on the worksheet in the range I4:K4, the formula above can easily be adapted to use the range directly like this:

=FILTER(B5:G12,ISNUMBER(MATCH(B4:G4,I4:K4,0)))

The range I4:K4 is evaluated as {“a”,“c”,“e”}, and behaves just like the array constant in the formula above.

Explanation

In this example, the goal is to list and count values that are duplicated in a set of data at least n times, where n is provided as a variable in cell D5. All data is in the named range data (B5:B16). In the worksheet shown, the formula used in cell F5 is:

=UNIQUE(FILTER(data,COUNTIF(data,data)>=D5))

Working from the inside out, the first step is to count the values in data . This is done with the COUNTIF function like this:

COUNTIF(data,data) // get all counts

Because there are 12 values in data , and data is used for both range and criteria , COUNTIF returns an array with 12 counts as a result:

{4;1;3;1;2;4;2;3;1;4;3;4} // result from COUNTIF

Each number represents the count of one value in data . For example, because “Red” is the first value in data , and because “Red” occurs 4 times total, the first number in the array is 4. The next step is to compare these counts to the “Min count” in D5:

=COUNTIF(data,data)>=D5
={4;1;3;1;2;4;2;3;1;4;3;4}>=D5

Cell D5 contains 2, so the result is an array of 12 TRUE and FALSE values like this:

={TRUE;FALSE;TRUE;FALSE;TRUE;TRUE;TRUE;TRUE;FALSE;TRUE;TRUE;TRUE}

Each TRUE in this array represents a value that occurs at least 2 times in the data. This array is returned directly to the FILTER function as the include argument , and FILTER uses the array to return values that correspond to TRUE. These are values that occur at least twice in the data:

{"Red";"Green";"Purple";"Red";"Purple";"Green";"Red";"Green";"Red"}

FILTER returns the array to the UNIQUE function , and UNIQUE returns unique values:

{"Red";"Green";"Purple"}

These values spill into range F5:F7 as the final result. Notice each of these values occurs at least 2 times in data .

Summary count

To get the summary count seen in column G, the formula in G5 is:

=COUNTIF(data,F5#)

With data as range , and the spill range F5# as criteria , COUNTIF returns the count that each value in column F appears in data .

Dynamic source range

Because data (B5:B16) is a normal named range, it won’t resize if data is added or deleted. To use a dynamic range that will automatically resize when needed, you can use an Excel Table , or create a dynamic named range with a formula.