• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Sum n lowest values until the item frequency in another column reaches a limit

kh999

New Member
Please remember to follow all forum rules: Cross-posting
Hi Guys,

I need help with a formula. I want to dynamically sum the lowest N values. In the below data, how can i find the sum of the lowest costing 9 item units?

Additionally, is there a way to list these lowest costing 9 units dynamically in a new table in the same format with the # of units specified?

Item# of UnitsCost per UnitTotal Item Cost
A101001000
B41144
C22244
D633198
E12222
 
cannot visualize what you want. Please show a mocked up solution based upon the data you have provided.
 
Sure. Sum of the lowest costing 9 item units = sum of (4 units of B + 2 units of C + 1 unit of E + 2 units of D) = 176.

The formula should sum the lowest values in column "cost per unit" until the corresponding sum in column "# of units" is 9.

Let me know if this is unclear.

Thanks for your help!
 
Regrettably, whilst I may have a solution, the techniques I use are not generally available.

69970
The solution as it stands uses
Code:
= LET(
unitCost, SORTBY(Availability[Cost per Unit],Availability[Cost per Unit]),
cumulativeUnits, ACCUMULATE(SORTBY(Availability['# of Units],Availability[Cost per Unit])),
cappedUnits, IF(cumulativeUnits<Required, cumulativeUnits, Required),
units, DIFF(cappedUnits, 0),
itemCosts, units * unitCost,
SUM(itemCosts) )

LET: Microsoft 365 beta
SORTBY: Microsoft 365
ACCUMULATE: Charles Williams SpeedTools
DIFF: Charles Williams SpeedTools

Some refactoring is required!
 
Regrettably, whilst I may have a solution, the techniques I use are not generally available.

View attachment 69970
The solution as it stands uses
Code:
= LET(
unitCost, SORTBY(Availability[Cost per Unit],Availability[Cost per Unit]),
cumulativeUnits, ACCUMULATE(SORTBY(Availability['# of Units],Availability[Cost per Unit])),
cappedUnits, IF(cumulativeUnits<Required, cumulativeUnits, Required),
units, DIFF(cappedUnits, 0),
itemCosts, units * unitCost,
SUM(itemCosts) )

LET: Microsoft 365 beta
SORTBY: Microsoft 365
ACCUMULATE: Charles Williams SpeedTools
DIFF: Charles Williams SpeedTools

Some refactoring is required!
Yes that's the solution I want :(
 
An alternative solution that performs the accumulation with a sequence of partial sums using SUMIFS:
The advantage is that the formula does not require the data sorted by cost.
69978

Since I gather you have chosen to cross-post, please do not neglect to inform each forum of any significant contribution made elsewhere.
Otherwise, a lot of time may simply be wasted.
 
Sure Peter! I have been able to solve using the 'small' function, which sorts the values first. I am using an extra tab but it's okay. Thanks for your prompt help!
 
Back
Top