Sum values in one column until values in another column reach a certain value

C_merr

New Member
Joined
May 26, 2016
Messages
19
I need to get the sum of the prices when the contract is ZS but need the sum per quantity of 10. So in this example, i need to find the sum of first 4 columns because that will make the quantity add up to 10. The problem is, i copy and paste in sets of data where the "ZS" contract will fill at a different number of prices that cause it to add up to a quantity of 10. in the end I am trying to make a calculator to calculate agricultural crush. I have been stuck on this for days, Please Help!

FIllIDCONTRACTPriceBuySellOrderTypeQuantity
1ZS10914BuyLMT1
2ZS10926BuyLMT1
3ZS10932BuyLMT1
4ZS10944BuyLMT7
5ZL3186SellLMT9
6ZM3982SellLMT11
7ZS10946BuyLMT10
8ZL3186SellLMT9
9ZM3982SellLMT11

<tbody>
</tbody>
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Well, you could start with a SUMIFS formula, to get the cumulative sum of all ZS's. Assuming your data table above is A1:F10, add this formula in G2, then drag it down to G10:

=SUMIFS(F$2:F2,B$2:B2,"ZS")

So that will give you the rolling sum, now you just need to pick out when it hits 10. If visually searching won't work, you could do this modification:

=If(SUMIFS(F$2:F2,B$2:B2,"ZS") <10 , "", SUMIFS(F$2:F2,B$2:B2,"ZS"))

Now, you can scan down the column, and the FIRST result you see will be your answer (though you will see additional results below that, they will need to be ignored)
 
Upvote 0
Well, you could start with a SUMIFS formula, to get the cumulative sum of all ZS's. Assuming your data table above is A1:F10, add this formula in G2, then drag it down to G10:

=SUMIFS(F$2:F2,B$2:B2,"ZS")

So that will give you the rolling sum, now you just need to pick out when it hits 10. If visually searching won't work, you could do this modification:

=If(SUMIFS(F$2:F2,B$2:B2,"ZS") <10 , "", SUMIFS(F$2:F2,B$2:B2,"ZS"))

Now, you can scan down the column, and the FIRST result you see will be your answer (though you will see additional results below that, they will need to be ignored)

This tells me when the quantity will add up to 10 for ZS, but i need a formula that will get the average price of the "ZS's" each grouping of a quantity of 10. i will then put this number into an equation. and it wont always be the same number of rows that it has to add up when i copy and paste each new order. If this is possible please let me know, Thank you for trying to help!
 
Upvote 0
I want the formula to do something like: If the contract is ZS, return the average price, per 10 contracts filled. if that makes sense?
 
Upvote 0
You're losing me on the 10 part. Is it 10 ZS contracts, or 10 ZS UNITS, because in your example, the first four ZS row quantity adds up to 10 (1+1+1+7)

Are you saying for every 10 ZS's in column B, you want the average of their quantities in column F?

if it's 10 UNITS, how would you ever guarantee that the quantities add up to even amounts of 10?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,759
Members
449,048
Latest member
excelknuckles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top