Summing Values in Google Sheets – How to Sum Values Based on Matching First Two Characters

google sheets

Seems like this should be simple but I'm having a hard time figuring it out.

I have data like this:

      A       B
1   Cr foo   1.00
2   Cr bar   2.00
3   Cr boo   0.50
4   Cr far   3.00

I want to sum column B where column A starts with "Cr". Obviously in the real data there are lots of other values in column A as well that do not start with "Cr".

I've been playing with using left() inside of the sumif, but I can't get it to work.

Best Answer

That would be

=sumif(A1:A, "Cr*", B1:B)

where A1:A is the range to which the condition is applied, Cr* is a pattern that matches any string beginning with Cr (here * stands for any number of any characters), and B1:B is the range of the values to be added.

One can also use query or filter for such operations. I wrote a summary of available functions: String matching in Google Sheets/Docs/Apps Script.