Where code (B5:B15) and qty (C5:C15) are named ranges. The result is a case-sensitive sum of quantities for each code listed in column E.
Unique values
To generate the list of unique values in the range E5:E8, you would normally use the UNIQUE function . However, UNIQUE is not case-sensitive, so it will not work in this situation. This article provides a formula that can extract unique values from a range of cells, taking into account upper and lowercase characters.
EXACT function
The EXACT function has just one purpose: to compare text in a case-sensitive manner. EXACT takes two arguments: text1 and text2. If text1 and text2 match exactly (considering upper and lower case), EXACT returns TRUE. Otherwise, EXACT returns FALSE:
Worksheet example
In the example shown, we have four codes in column E, and we want to sum the values in column C using the codes that appear in column B. In other words, we want to sum the total quantity per code, and this calculation needs to be case-sensitive. For convenience, code (B5:B15) and qty (C5:C15) are named ranges. The formula in E5, copied down, is: Working from the inside-out, we are using the EXACT function to compare each code in column E with the named range code (B5:B15): EXACT compares the value in E5 (“ABC”) to all values in B5:B15. Because the range contains 11 cells, EXACT returns 11 results (one for each code) in an array like this: Each TRUE represents an exact match of “ABC” in B5:B15. Each FALSE represents a non-match. Next, we use a double-negative (–) operation to convert TRUE and FALSE values into 1’s and 0’s. The resulting array looks like this: Note: technically, the double negative (–) is unnecessary in this formula, because multiplying the TRUE and FALSE values by the numeric values in qty will automatically convert TRUE and FALSE values to 1s and 0s. However, the double negative does no harm and it makes the formula a bit easier to understand, because it signals a Boolean operation. At this point, we can simplify the formula like this: Next, we need to perform the multiplication step and sum things up.
SUMPRODUCT function
SUMPRODUCT is a versatile function that appears in many formulas because it can handle array operations natively in older versions of Excel. In this case, the array operation is performed by the EXACT function in the previous step. The remaining steps look like this: As you can see, the array returned by EXACT behaves like a filter that “cancels out” values in qty that are not associated with the code “ABC”. With just one array to process in the end, SUMPRODUCT sums all numbers in the array and returns the final result: 19. As the formula is copied down, we get the correct sum for each code in column E, taking into account upper and lower case characters. Note: Because SUMPRODUCT can handle arrays natively, it is not necessary to use Control+Shift+Enter to enter this formula. In Excel 365, you can replace SUMPRODUCT with the SUM function. To read more about this, see Why SUMPRODUCT?
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.