I have an excel table:
JobA .03445
JobB .01366
JobC .93271
JobD .6335
Plus 65,000 more.
What I need to do, is to create four equal buckets based on the values. where the sum of all Jobs in each bucket come as close to the other three buckets as possible.
Is there a way to do this in Excel?
Thanks
You can try this approach based on the incremental percentage. So you sum each incremental job until your sum reaches 25% of total values (that is BucketA), jobs from 25-50% will be "BucketB", 50-75% "BucketC", and rest will go into "BucketD". Sum of values in each bucket should be pretty close since you have 65k of values.
enter this formula
=IF(SUM($B$2:B2)/SUM($B$2:$B$100000)<0.25,"BucketA",IF(SUM($B$2:B2)/SUM($B$2:$B$100000)<0.5,"BucketB",IF(SUM($B$2:B2)/SUM($B$2:$B$100000)<0.75,"BucketC","BucketD")))
in cell C1 and drag it to the bottom.
There's lots of studies into algorithms that solve these types of problems. Your problem is actually the exact same format as the equal piles example in this article:
https://simple.wikipedia.org/wiki/P_versus_NP#Example
Considering the volume you're working with and the fairly narrow range of values, you could get a fairly good approximate solution by simply doing this:
Sort all items in descending order by value
In an adjacent column, put 1, 2, 3 and 4 against the first 4 values.
Use autofill to repeat that pattern against all values
You should now have 4 groups of fairly equal value
Related
I spent hours trying to look for a solution and I feel like I got close but figured asking would be the best way.
Lets say I have a table with 2 columns, column A is an item, and column B is a price for the item. This table has 12 entries. What I would like to do is generate additional tables of 6 entries that do not exceed a certain price. see below for example. The number i want these table to not exceed is 50,000.
for example the first entry could be an apple at 9,000 value. the apple is column a, and value column b.
Can someone help with a way to generate all combinations of 6 items from column a, that do not exceed a combined price of 50,000 in column b?
With 12 items you have 212-1 or 4095 possible combinations of products. These can map into the 12 bits of a 12-bit binary number. It is not difficult to write a macro to calculate the total cost of each combination and then filter the result to display results less than or equal to 50,000.
EDIT#1:
Please see:
Best possible combination sum of predefined numbers that smaller or equal NN
Listing all possible combination without repetition,VBA
I would like to tell, with a smaller number of columns.
Let's say we have a sum of 24 and we want to distribute it randomly into 10 separate columns. we should get such a result as below I wrote.
Is there a formula in Excel like this?
Thanks in advance.
Ok. Here is what I would do...
For each required split, select a random number between zero and the remainder of the distribution qty, multiplied by the percentage of how many splits have already been calculated. This prevents the first few splits being very high, and the rest being zero.
I would also add a check for the very last split to make sure that it equals whatever is left of the original distribution qty.
Here is an image for illustration and the formula that I have used:
=IF($A2=MAX($A:$A),$F$1-SUM($B$1:$B1),RANDBETWEEN(0,($F$1-SUM($B$1:$B1))*($A2/MAX($A:$A))))
Hopefully, this isn't too complex to understand. If you need further explanation, please let me know.
You can simply change the distribution qty in the yellow box, and if you want more splits, all you need to do is drag down columns A & B to the required number.
So this is the simplified question I broke down from a former question I had here: Excel help on combination of Index - match and sumifs? .
For this one, I have Table1 (the black-gray one) with two or more columns for adjustments for various order numbers. See this image below:
What I want to achieve is to have total adjustments for those order numbers that contain the numbers in Total Adjustment column in the blue table, each of which will depend on the cell beside it.
Example: Order number 17051 has two products: 17051A (Apple) and 17051B (Orange).
Now what I want to achieve in cell C10 is the sum of adjustment for both 17051A and 17051B, which will be: Apple Adjustment (5000) + Orange Adjustment (4500) = 9500.
The formula I used below (and in the image) kept giving me error messages, and this happens even before I add the adjustment for Orange.
=SUMIF(Text(LEFT(Table1[Order Number],5),"00000"),text(B10,"00000"),Table1[Apple Adjustment])
I have spent the whole day looking for a solution for this and didn’t even come close to find any. Any suggestion is appreciated.
Assuming your headers always have the text "adjustment" in them, you could use:
=SUMPRODUCT((LEFT($B$4:$B$7,5)=B10&"")*(RIGHT($C$3:$F$3,10)="adjustment")*$C$4:$F$7)
In C10 you could add two sumproducts. This assumes that products are always 5 numbers long at the start. If not swop the 5 to use the length of the product reference part you are matching on.
=SUMPRODUCT(--(1*LEFT($B$4:$B$7,5)=$B10),$D$4:$D$7)+SUMPRODUCT(--(1*LEFT($B$4:$B$7,5)=$B10),$F$4:$F$7)
Which with table syntax is:
=SUMPRODUCT(--(1*LEFT(Table1[Order Number],5)=$B10),Table1[Apple Adjustment])+SUMPRODUCT(--(1*LEFT(Table1[Order Number],5)=$B10),Table1[Orange Adjustment])
Using LEN
=SUMPRODUCT(--(1*LEFT(Table1[Order Number],LEN($B10))=$B10),Table1[Apple Adjustment])+SUMPRODUCT(--(1*LEFT(Table1[Order Number],LEN($B10))=$B10),Table1[Orange Adjustment])
I am multiplying by 1 to ensure Left, 5 becomes numeric.
I have a data list in Excel, I am looking to take the top 3 values for each number, and get the average for those 3 values quickly. I often work with lists of up to 50,000 lines which at any one time could convert to over 10,000 different column A numbers.
I understand basic pivot tables to get an average after the top 3 values are collected, but need to find a way to remove all values that are not the top 3,
I trust this may be an extremely simple ask, or complex and thank you in advance for your help.
you can use =LARGE(Array, k) formula. For example, =LARGE(B:B, 1) is for 1-largest number, =LARGE(B:B, 2) is for 2-largest number etc.
If column contains many duplicates, and you want to get all occurences of top three values, use this formula to get all of them (put:
=IF(LARGE(B:B,ROW(A1))>=LARGE(B:B,COUNTIF(B:B,LARGE(B:B,COUNTIF(B:B,MAX(B:B))+1))+COUNTIF(B:B,MAX(B:B))+1),LARGE(B:B,ROW(A1)),"")
Working an a project with many more possible combinations and I'm not sure how to approach it, so I'm going to ask how to do it on a smaller scale and then apply it to a larger scale.
I have to buy 1 of product A and 1 of product B
They both come in 100 varieties at different prices.
For product A:
TABLE 1 (A1:B6)
Dollars-Versions
1-15
2-20
3-30
4-20
5-15
and Product B
TABLE 2 (C1:D6)
Dollars-Versions
1-40
2-30
3-20
4-5
5-5
I know the minimum I can spend is $2 (600 combinations) & the Max is $10 (75 combinations), and there are 10000 (100x100) total combinations
If I put the dollar values 2-10 in cells E2:E10, is there a formula to quickly determine the number of combinations for each net dollar value in cells F2:f10?
I imagine it would have to be done with an sumif array formula, but I can't start to figure out what it would be. If I had a small data set like this, I would make a crosstab, but my data set is too large to do it efficiently.
Thank you in advance!
You would need a formula like this:-
=SUM((A$2:A$6+TRANSPOSE(C$2:C$6)=F2)*B$2:B$6*TRANSPOSE(D$2:D$6))
which would have to be entered as an array formula using CtrlShiftEnter
It builds up a 2D array with ones at the elements where the corresponding cells in the two lists add up to the amount you have to spend, then multiplies it by the corresponding numbers of combinations.