where data is the named range B5:B15. Note: I learned this formula from fellow Excel MVP, Sergei Baklan .

REDUCE function

The REDUCE function applies a custom LAMBDA function to each element in a given array and accumulates results to a single value. The generic syntax for the REDUCE function looks like this: The calculation performed by REDUCE is determined by a custom LAMBDA function with this generic syntax: The first argument, a, is the accumulator. The accumulator begins as the initial_value provided to REDUCE and changes as REDUCE loops over the elements in array and applies a calculation. The v represents the value of each element in array. Calculation is the formula logic that creates the final accumulated result.


In the worksheet shown, the formula in cell D5 is: Notice that intitial_value is purposely not provided, because we want to start with a null value. The custom LAMBDA function inside of REDUCE looks like this: At a high level, the REDUCE function loops over the values in data one at a time. At each new value, v, the custom LAMBDA function checks if v is already in the accumulator, a. If v is already in a, the current value of a is returned. If v is not already present in a, the function combines a and v with the VTSACK function. The final result is an array that contains case-sensitive unique values.


The EXACT function is what makes this formula case-sensitive, and the IF function is used to test values and control flow: The logical_test inside of IF is based on the EXACT function and the SUM function: Normally, the EXACT function checks if two values are exactly equal, including upper and lowercase characters. In this case, EXACT is comparing a and v. Because a is an array, the result will be an array of TRUE and FALSE values. The double negative (–) is used to convert the TRUE and FALSE values from EXACT into 1s and 0s, which are then summed by the SUM function. If SUM returns a positive number (which evaluates to TRUE in Excel), it means the v already exists in a, and IF returns a. If SUM returns zero (which evaluates to FALSE in Excel), it means v does not yet exist in a, and IF runs the VSTACK function, which is configured to combine a and v by stacking v vertically below a.

Dave Bruns

Hi - I’m Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.