where data is the named range B5:B16, and each text string includes both a label and a number separated by a single space (" “). See below for more details and for the formulas used to generate the summary table in E7:F9.

### Total sum

To sum all the numbers that appear in B5:B16, ignoring text, the formula in E5 is: Working from the inside out, the TEXTAFTER function is used to extract the numbers like this: TEXTAFTER is configured to extract the text that occurs after a single space character (” “). Because we are giving TEXTAFTER 12 separate text strings in data (B5:B16), TEXTAFTER returns 12 results in an array like this: Notice that at this point the numbers are still text, as you can see by the double quotes (”). To coerce these text strings into actual numbers, we use a double negative (–): The result is an array that contains numbers only: This array is returned directly to the SUM function: SUM returns 194 as the final result.

### Summary table in two parts

One easy way to create the summary table seen in the worksheet is to use two formulas, one to list unique colors, and one to sum the numbers associated with each color. To list the unique colors starting in cell E8, you can use: This is a variation of the formula explained above. Instead of using TEXTAFTER, we are using the TEXTBEFORE function to get the text before the space (" “): TEXTBEFORE returns an array of 12 colors like this: This array is returned directly to the UNIQUE function, which returns an array with 5 unique colors: The array is returned to cell E8, and spills into the range E8:E12. To sum the numbers associated with each color in column F, you can enter this formula in cell F8 and copy it down: Note: we can’t use the SUMIF function in this case (which would be easier) because we don’t have the colors without numbers in an actual range. Instead, the colors exist in an array returned by the TEXTBEFORE function. SUMIF requires a range for the range argument.

### All-in-one summary table

To create an all-in-one summary table that lists the unique dates along with a count for each date, you can use an advanced formula like this: This is how the formula looks in the worksheet:

This formula utilizes the same patterns used in the formulas explained above, but now we move into more advanced functions like LET, LAMBDA, and BYROW. The LET function is used to assign intermediate results to named variables. First, we use TEXTBEFORE to separate the colors from the numbers and assign the result to c. We use TEXTAFTER to separate the numbers and assign the result to n. Then we feed c into UNIQUE (to get unique colors) and assign the result to u. Next, we use the HSTACK function to combine two arrays. Array1 is u (the unique colors), and array2 is generated with the BYROW function: BYROW loops through each unique color in u and runs a custom LAMBDA function to sum the numbers associated with each color: The sum is generated with boolean logic and the SUM function: The first part of the expression checks all colors (c) against the current row (x), generating an array of TRUE and FALSE values: The double negative (–) converts the TRUE and FALSE values to 1s and 0s. This array is then multiplied by all numbers (n). The numbers that survive are associated with the current row color (x) and the other numbers are converted to zero. SUM then returns the result for that row. Note: Technically, the double negative (–) operation is not needed above because the multiplication step will automatically coerce the TRUE and FALSE values to 1s and 0s. However, it does no harm and perhaps makes the pattern of this formula easier to understand. In addition, if you remove the multiplication step, the result will be a count of each color rather than a sum. So the double negative allows the count variation of the formula to work without further adjustment. The final result from the BYROW is an array with 5 sums: This array is returned to HSTACK as array2. HSTACK joins array1 and array2 together horizontally, and returns a 2-column array as a final result.

### 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.