Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sum values if any cell in corresponding row matches text

I have the following Google Sheets data:

Name1   Name2   Name3    Value
A       B       C        20
B       A       C        30
C       D       F        40

What I'm trying to do is see if a specific name appears in any of the three name columns. If it does, then sum all the values in the "Value" column for all matching rows.

For example, I want to sum all of the values for name "A". That name only appears on the first two rows, so it should do 20+30 to give me 50. If I change the searched name to "C", that appears in all three rows so it should sum all of the numbers: 20+30+40. The algorithm needs to adjust and search appropriately.

like image 889
void.pointer Avatar asked Oct 21 '22 13:10

void.pointer


1 Answers

=DSum will work

With the example you give use

=dsum(A1:D4,D1,{A1;"A"})+dsum(A1:D4,D1,{B1;"A"})+dsum(A1:D4,D1,{C1;"A"})

You can swap the "A" for a Cell reference

see https://drive.google.com/previewtemplate?id=0As3tAuweYU9QdEVHdTFHNzloSTY4LVYxdW9LdHRHbEE&mode=public#

like image 91
eddyparkinson Avatar answered Nov 09 '22 13:11

eddyparkinson