Using Query
The QUERY function is better suited to SUM the values in Column B grouped by the values in Column A.
Syntax: QUERY(data, query, [headers])
=QUERY(A1:B5, "select A, SUM(B) group by A")

Below are some variations on the formula above.
Exclude Blanks +----------------------------------------+ | =QUERY(A:B, "select A, SUM(B) | | where A <> '' group by A") | +----------------------------------------+ Custom Headings +----------------------------------------+ | =QUERY(A:B, "select A, SUM(B) | | where A <> '' group by A | | Label A 'Key', SUM(B) 'Total'") | +----------------------------------------+ No Headings +----------------------------------------+ | =QUERY(A:B, "select A, SUM(B) | | where A <> '' group by A | | Label A '', SUM(B) ''") | +----------------------------------------+
UNIQUE , SUMIF, ARRAYFORMULA
An alternative approach/formula uses the UNIQUE and SUMIF functions. Those functions are then wrapped in an ARRAYFORMULA so that one formula will populate all the necessary rows.
={ UNIQUE(A1:A4), ARRAYFORMULA(SUMIF(A:A, UNIQUE(A1:A4), B:B)) }
