-1

I am trying to calculate miles driven for two different companies. I want to make a cell that will add up only data from Company A, and a cell that will add up data from only Company B.

EX:

COMPANY       DAYS MILAGE TOTAL        COMPANY A TOTAL     COMPANY B TOTAL    
COMPANY A      10                            20               40

COMPANY B      20

COMPANY A      10

COMPANY B      20

Does this make sense?

1
2

You can do something like this:

=QUERY(A2:B,"SELECT SUM(B) WHERE B IS NOT NULL PIVOT A")

or

=SUMIF($A2:A,"=" & C2,$B2:B)    // copy this into the adjacent cell 

or

=SUM(FILTER($B2:B,$A2:A=C2))    // copy this into the adjacent cell 

See example file I created: Milage per Company

Remark

  • The first solution is the shortest, because it covers two answers in the same query. It automatically "grows", when you start adding different companies. If you add something in column B, without adding something in column A, the table will get messed up. Add a company in column A again will return the table to normal.
  • The second is the most straightforward of them all.
  • The third solution allows for some additional tweaking afterwards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.