Explanation

The dropdown is set up with a simple data validation rule based on a “list”:

Red,Blue,Green,All

The named ranges “color” (C5:C15) and “qty” (D5:D15) are for convenience only.

The formula in G5 performs a conditional sum based on the current dropdown selection in F5. The outermost function is an IF statement, which checks if the selection is “all”:

=IF(F5="all",SUM(qty)

If so, the formula returns the sum of quantity column as a final result.

If F5 is any value except “all” (i.e. “red”, “blue”, or “green”), the logical test returns FALSE and IF routes the formula to the SUMIF function:

SUMIF(color,F5,qty)

SUMIF calculates a conditional sum based on the value in F5 and returns the result.

Explanation

The SUMPRODUCT function multiplies ranges or arrays together and returns the sum of products. This sounds boring, but SUMPRODUCT is an elegant and versatile function, which this example illustrates nicely.

In this example, SUMPRODUCT is configured with two arrays . The first array is the range that holds product pricing:

$C$5:$C$9

Note the reference is absolute to prevent changes as the formula is copied to the right. This range evaluates to the following array:

{99;69;129;119;49}

The second array is generated with this expression:

--(D5:D9="x")

The result of D5:D9=“x” is an array of TRUE FALSE values like this:

{TRUE;TRUE;FALSE;FALSE;FALSE}

The double negative (–) converts these TRUE FALSE values to 1s and 0s:

{1;1;0;0;0}

So, inside SUMPRODUCT we have:

=SUMPRODUCT({99;69;129;119;49},{1;1;0;0;0})

The SUMPRODUCT function then multiplies corresponding items in each array together:

=SUMPRODUCT({99;69;0;0;0})

and returns the sum of products, 168 in this case.

Effectively, the second array acts as a filter for the values in the first array. Zeros in array2 cancel out items in array1, and 1s in array2 allow values from array1 to pass through into the final result.

With a single array

SUMPRODUCT is set up to accept multiple arrays, but you can simplify this formula a bit by providing a single array at the start:

=SUMPRODUCT($C$5:$C$9*(D5:D9="x"))

The math operation (multiplication) automatically coerces the TRUE FALSE values in the second expression to ones and zeros, with no need for a double negative.