SOLVED

Sum of All Product?

%3CLINGO-SUB%20id%3D%22lingo-sub-2760414%22%20slang%3D%22en-US%22%3ESum%20of%20All%20Product%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2760414%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20do%20I%20get%20the%20total%20of%20all%20apples%20in%20the%20below%20table%20in%20one%20simple%20formula%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CTABLE%20width%3D%22258%22%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%2255%22%3E%3CSTRONG%3EProduct%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%20width%3D%2231%22%3E%3CSTRONG%3EQTY%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%20width%3D%2255%22%3E%3CSTRONG%3EProduct%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%20width%3D%2231%22%3E%3CSTRONG%3EQTY%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%20width%3D%2255%22%3E%3CSTRONG%3EProduct%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%20width%3D%2231%22%3E%3CSTRONG%3EQTY%3C%2FSTRONG%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EApple%3C%2FTD%3E%3CTD%3E1%3C%2FTD%3E%3CTD%3EApple%3C%2FTD%3E%3CTD%3E1%3C%2FTD%3E%3CTD%3EApple%3C%2FTD%3E%3CTD%3E7%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EApple%3C%2FTD%3E%3CTD%3E2%3C%2FTD%3E%3CTD%3EApple%3C%2FTD%3E%3CTD%3E1%3C%2FTD%3E%3CTD%3EApple%3C%2FTD%3E%3CTD%3E2%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EOrange%3C%2FTD%3E%3CTD%3E1%3C%2FTD%3E%3CTD%3EOrange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3E1%3C%2FTD%3E%3CTD%3EApple%3C%2FTD%3E%3CTD%3E1%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2760414%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2760486%22%20slang%3D%22en-US%22%3ERe%3A%20Sum%20of%20All%20Product%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2760486%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1159056%22%20target%3D%22_blank%22%3E%40Qinnab%3C%2FA%3E%26nbsp%3BYou%20could%20use%20SUMIF%20as%20demonstrated%20in%20the%20attached%20file.%20It's%20not%20very%20elegant%20though%20and%20perhaps%20your%20real%20life%20situation%20isn't%20as%20simplistic%20as%20your%20example%20suggests.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2760555%22%20slang%3D%22en-US%22%3ERe%3A%20Sum%20of%20All%20Product%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2760555%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%2C%20it%20is%20a%20kind%20of%20real-life%20situation%2C%20I%20have%20multiple%20columns%20(%20Stores)%20that%20I%20need%20to%20get%20the%20total%20of%20products%20in.%26nbsp%3B%3C%2FP%3E%3CP%3EI%20know%20how%20to%20get%20it%20in%20long%20formula%20using%20sumproduct%2C%20but%20I%20still%20believe%20there%20is%20an%20easier%20way%20to%20do%20it%2C%20maybe%20Vlookup!%20I%20just%20can't%20figure%20it%20out.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2760581%22%20slang%3D%22en-US%22%3ERe%3A%20Sum%20of%20All%20Product%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2760581%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1159056%22%20target%3D%22_blank%22%3E%40Qinnab%3C%2FA%3E%26nbsp%3BHow%20many%20stores%3F%20I%20suspect%20more%20than%20a%20couple%2C%20thus%20the%20formula%20will%20indeed%20get%20very%20clumsy%20with%20SUMPRODUCT%20or%20SUMIF.%3C%2FP%3E%3CP%3EDo%20you%20have%20any%20influence%20over%20how%20the%20store%20data%20get%20assembled%3F%20Why%20in%20columns%2C%20side-by-side%3F%20If%20you%20can%20get%20it%20all%20in%20three%20columns%20(Store%2C%20Product%2C%20Qty)%2C%20you%20could%20do%20it%20in%20the%20blink%20of%20an%20eye%20with%20a%20pivot%20table.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2760594%22%20slang%3D%22en-US%22%3ERe%3A%20Sum%20of%20All%20Product%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2760594%22%20slang%3D%22en-US%22%3EI%20have%209%20stores%20with%209%20quantities%20in%20columns%20beside%20it%2C%20I%20have%20no%20control%20over%20storing%20this%20data%20since%20this%20is%20an%20output%20of%20several%20formulas%20within%20many%20sheets%20too.%20I%20believe%20Sum%20and%20Vlookup%20should%20be%20used%20here%20somehow!%20for%20now%2C%20I%20will%20settle%20with%20Sumif%20until%20I%20figure%20an%20easier%20way.%20Thank%20You%20very%20much%20for%20your%20help.%3C%2FLINGO-BODY%3E
New Contributor

Hi, 

How do I get the total of all apples in the below table in one simple formula? 

 

ProductQTYProductQTYProductQTY
Apple1Apple1Apple7
Apple2Apple1Apple2
Orange1Orange1Orange1
Olive1Olive1Olive1
Banana1Banana1Banana1
Olive1Olive1Olive5
Olive1Olive1Olive1
Apple1Apple1Apple1
Apple3Apple1Apple1
Apple1Apple1Apple1
10 Replies
best response confirmed by Qinnab (New Contributor)
Solution

@Qinnab You could use SUMIF as demonstrated in the attached file. It's not very elegant though and perhaps your real life situation isn't as simplistic as your example suggests.

 

Thanks @Riny_van_Eekelen , it is a kind of real-life situation, I have multiple columns ( Stores) that I need to get the total of products in. 

I know how to get it in long formula using sumproduct, but I still believe there is an easier way to do it, maybe Vlookup! I just can't figure it out. 

@Qinnab How many stores? I suspect more than a couple, thus the formula will indeed get very clumsy with SUMPRODUCT or SUMIF.

Do you have any influence over how the store data get assembled? Why in columns, side-by-side? If you can get it all in three columns (Store, Product, Qty), you could do it in the blink of an eye with a pivot table.

I have 9 stores with 9 quantities in columns beside it, I have no control over storing this data since this is an output of several formulas within many sheets too. I believe Sum and Vlookup should be used here somehow! for now, I will settle with Sumif until I figure an easier way. Thank You very much for your help.

@Qinnab You're welcome! But if you get the data into an Excel file, you could just copy and paste the store info in one long list and then create the pivot table. Or if that is still too much work, consider PowerQuery (PQ). You can easily divide the information for the 9 stores (two columns each) into separate named ranges or tables. Connect to them with PQ, append them and clean-up a bit. Set it up correctly once, and you can use it over-and-over again.

@Qinnab The attached file now contains an example of a PQ solution.

@Qinnab 

Array methods will perform calculation using your data as it stands, but is better with Excel 365.  The first approach works with legacy Excel

= SUMIFS(QtyTable, ProductTable, ProductList)

where the quantity table is simply the product table offset one cell to the right.

 

@Qinnab 

One more similar variant for the collection

References:

=SUM(
   MMULT( --( COLUMN($B$2:$G$2) = COLUMN($B$2) ),
   MMULT( TRANSPOSE( --($B$3:$G$12=$I2) ),
          IF( ISNUMBER($B$3:$G$12), $B$3:$G$12, 0 )
   ) )
 )

Named ranges:

=SUM(
    MMULT( --( COLUMN(Headers) = CELL("col", Headers ) ),
    MMULT( TRANSPOSE( --(Data=$I2) ),
           IF( ISNUMBER(Data), Data, 0 )
    ) )
 )

Table:

=SUM(
    MMULT( --( COLUMN(Shops[#Headers]) = CELL("col", Shops[#Headers] ) ),
    MMULT( TRANSPOSE( --(Shops=$I2) ),
           IF( ISNUMBER(Shops), Shops, 0 )
    ) )
 )
That's pretty devious. The conversion to a Table should make the worksheet far easier to use though.

@Peter Bartholomew 

That was only to illustrate differences in using range references, named ranges and tables when the size of the range is relatively dynamic. For that the person need to play with variants using this or that formulae suggested.