Excel group cells in a table based on their combined total value - excel

i would like a list of client names where together they have a combined amount of 1000. so, say if jim and tod's combined amount of money <= 1000 and jim, tod, jill >= 1000 then list jim and tod in a cell, then in the next cell if jill, joy, and pat <=1000 and jill, joy, pat, and tam >= 1000 then list jill, joy, and pat and so fourth until all of the clients are in a list.
Is this possible? I am learning and am not sure where to start so i would greatly appreciate if someone can help point me in the right direction to solve this problem?

Assuming your criterion for a group is that the money sums to less than or equal to 1000, then this is straightforward. Simply accumulate the Money amount down the list of names and start a new group and (reset the accumulator) whenever the cumulative amount exceeds 1000.
This gives you the group number for each name (see column D in picture below). A separate problem is then to list the names for each group number. In the picture, I have allowed for a maximum of 5 names per group but if real data indicates this is insufficient then allowing more is straightforward.
The set of groups obtained using this approach is dependent on the ordering of the rows of input data - change this ordering and the result is a different set of groups.
Perhaps a more interesting and challenging problem is to define a set of groups which meet not only the <=1000 criterion but also other criteria such as: minimise number of groups overall and equalise, as far as possible, the total money allocated to each group. But that is a very different problem!

Related

Efficiency question with excel using index match for each cell in a large sheet

I have a 4 types of customers, each pay in a different payment plan.
group 1 - monthly
group 2 - semi monthly
group 3 - bi weekly
group 4 - weekly
I have a sheet with a range of all the relevant payment dates for those group sorted in the right order in row 1
I would like that for each customer there will be a data validation list (group 1,group 2, group 3,group 4)
When selected the customer's row will populate on the correct dates according to his group number and the date the payment starts.
My work around to do that was to create 4 separate sheets for each group, auto populate from the correct date and run it for all customers in each group meaning you can see for John Doe what and when will be his payments in each group even though he is in group 3 for example. And a MAIN sheet where John Doe has group 3 selected where a MATCH and INDEX is running to find when he is supposed to pay and how much. The issue is that for 400 rows and 300 column this becomes heavy.
How would you go about solving that?
each cell looks like this in the MAIN sheet
=LET(mothlydate,Monthlyrd3!$BK$3:AAC$3,semidate,Monthlyth16!$BK$3:ZZ$3,namemonthly,Monthlyrd3!$BK79:AAC79,namesemi,Monthlyth16!$BK79:ZZ79,
IF(OR($BA96="Monthly 3 rd",$BA96="Semi-Monthly",$BA96="Monthly 16 th"),
IF((IF(IFERROR(INDEX(namemonthly,1,MATCH(GH$2,mothlydate,0)),"")+IFERROR(INDEX(namesemi,1,MATCH(GH$2,semidate,0)),"")>$AE96,$AE96,IFERROR(INDEX(namemonthly,1,MATCH(GH$2,mothlydate,0)),"")+IFERROR(INDEX(namesemi,1,MATCH(GH$2,semidate,0)),"")))=0,"",(IF(IFERROR(INDEX(namemonthly,1,MATCH(GH$2,mothlydate,0)),"")+IFERROR(INDEX(namesemi,1,MATCH(GH$2,semidate,0)),"")>$AE96,$AE96,IFERROR(INDEX(namemonthly,1,MATCH(GH$2,mothlydate,0)),"")+IFERROR(INDEX(namesemi,1,MATCH(GH$2,semidate,0)),"")))),
IF($BA96="Bi-Weekly 1",(IFERROR(INDEX(NewBiWeekly!$BK79:AAC79,1,MATCH(GH$2,NewBiWeekly!$BK$3:AAC$3,0)),"")),IF($BA96="Bi-Weekly 2",(IFERROR(INDEX(NewBiWeeklyTwo!$BK79:AAC79,1,MATCH(GH$2,NewBiWeeklyTwo!$BK$3:AAC$3,0)),"")),IF($BA96="Other",(IFERROR(INDEX(NewOther!$BK79:AAC79,1,MATCH(GH$2,NewOther!$BK$3:AAC$3,0)),""))))))
)
THANKS!!!
This is based on a purely textual analysis of your formula, since data required for a meaningful analysis hasn't been forthcoming:
the expression below occurs 4 times in your formula
IFERROR(INDEX(namesemi,1,MATCH(GH$2,semidate,0)),"")
as does this one
IFERROR(INDEX(namemonthly,1,MATCH(GH$2,mothlydate,0))
which means that, in the worst-case circumstances, one or both expressions are being evaluated on FOUR separate occasions - it would be sensible to consider making one or both of these named 'values' at the start of the LET() function, such that, in the worst-case cirumstances going forward, each would be evaluated only once.

Dividing vector into groups by another vector

I have the following table (for example, the real table is 100 rows):
It has a group name column, n students in group, and score.
I would like to build a forth column of cluster, which will divide the groups into 10 decimils of approximatly equal size, while preserving the score. So if i have a total number of 80 students in all groups together, than I'll have 10 clusters which have about 8 students each one more or less. the top cluster will consist the groups with the highest grade.
I hope it makes any sense.
My problem is more an algorithmic one, I prefer to have a solution in excel/vba other than R just because I need a more dinamic solution.
I tried to do it manually by sorting the groups by score, and then summing the n of students until i get a number close to the decimil of the total number of students, but maybe there is an algorithem more precise and less frustrating than that.
Thanks

Substract a cell (if it has a # value) with rows below it in a different column if the conditions are the same

I'm using this equation =IF(K2=0,0, K2-I2) to show the difference in a cell with what a client has to pay vs what he has paid (negative if he paid less than what he had to and positive if he paid more). How would I modify this equation to substract from the next amount paid (k3 in this case) or the following (k4) if they didn't pay in k3 so the difference becomes 0 if its used with the added condition that the name at Column C matches.
The first column is the amount someone needs to pay, the second is what they paid, the fourth shows the difference and the fifth states what it is. I would like the difference from the first row to use the paid amount from the second row to substract from it before applying itself to the difference in the second row. Is this possible? I've tried looking for hours in google with no luck.
Edit:
This is how I would like it to look (this is manually inputting the data). The amount the client has to pay each month is 425.65 so the second month he pays 400 it would first cancel the first 'debt' to then count towards his second month payment which results in more debt than the first pay cycle.
Prelim
Worksheet here / screenshot below refer.
If you don't mind using a 'helper' column (I don't see any other way around this, unless you go down the 'VBA/Pivot' route, given the nature of the sum function re arrays) - then this should (I think!:) address the issue...
Eqns
Helper
=IF(OR(B3<>B4,SUM(D$3:D3*(B$3:B3=B3))>=INDEX($C$3:$C$11,MATCH(B3,$B$3:$B$11,0))),1,0)
This turns 1 when the sum of "Paid" is at least >= "Owing" for the same individual. Assumes: rows ordered chronologically, grouped by 'Person' attribute.
Net ultimate
=IF(B3=B2,"",SUM(D3:INDEX($D$3:$D$11,MATCH(B3&1,$B$3:$B$11&$E$3:$E$11,0))))
Screenshots
This sums from the first instance of 'Paid' for a given Person, to the Paid value corresponding to the first instance of a '1' in the Helper column.
Examples
In this case, A owes £1k at outset, pays £450 initially, then pays a further £700 (i.e. has overpaid by £150). As such, the 'Net ultimate' figure reports back £1,150 (=£450 + £700); it doesn't consider the £50 (did you want it to? If so the function becomes a lot easier, and reduces to a regular sumifs...).
For B: net ultimate = £1,025 (the total amounts paid never exceed what is owing, so tally all amounts paid by B)
Same goes for £1k and C....

How do I distribute a value over multiple cells evenly but under a maximum limit?

Example data with desired outcome that I need to calculate
I have 12 items of a certain current value. I have a 'soft' cap of $1,000,000 for these values. Some of the items fall above, and some below this cap level.
I have an amount of money (for this example $900,000) that I want to distribute amongst only the items that fall below the cap (in this example 6 items), with the aim of bringing the value of these items up to but not over the cap value.
If I distribute the $900,000 evenly over these 6 items (each receiving $150,000), you can see that items 2 and 9 would then be over the $1,000,000 cap. So items 2 and 9 should only receive $100,000 to raise their value to the cap, then the remaining 4 items would receive and equal share on the remaining pool of money ($700,000 / 4 = $175,000).
So I need a formula to check every item to see if it needs a distribution (i.e below the cap) and then portion/divide out the money pool as illustrated above in the desired distribution column.
Note: The pool of money to be distributed can change. Also the number of items below the cap can change. The cap value itself can change.
I am hoping to avoid VBA or Solver because the spreadsheet could be used on other people's computers.
Hopefully this makes sense. Thanks.
EDIT:
So far I have been able to get close by adding a helper column and using the following formula:
=IF(SUM($F$6:F14)=$D$23,0,E15*MIN(D15,($D$23-SUM($F$6:F14))/SUM(E15:$E$18)))
Working example when values are sorted.
This seems to work when the values are sorted in descending order, as shown in the example image above. But seems to break when the values are a bit more randomly assorted which is likely to happen (as in the original post).
Just to give you an idea of how the solver can be set up to do a capital budget model here is one, also shows the solver and its settings:

Sum unique values based on another column

I have four values: Name, Maturity, Hasinteracted?, SizeofName
Entity (Constant) - represents the name of the entity.
Maturity (Variable) - In months, how long have they been active with us (i.e. 1 would be one month etc)
Hasinteracted? (True, False) - If yes, their value is TRUE
SizeofEntity (constant) - How large is this entity? This value varies for different Names but is constant for its' own name (i.e. Entity A will always be 12 regardless of their maturity, while Entity B will be 19 regardless of their maturity)
What I am trying to do:
Using a PivotTable, I have been able to create a table which has Maturity in the rows, and count of interactions for each maturity in the column.
The part that I am struggling with is the total SizeofEntity. Basically, I want it to sum the total SizeofEntity. The issue is that if Entity A repeats in the name section, it will double in this calculation.
Example
Entity A shows once (size = 12) in maturity 1 and maturity 2, Entity B shows once (size = 19) in maturity 1.
What I am hoping to see in the value section is the total SizeofEntity in Maturity 1 being 31 and 12 in Maturity 2, which occurs.
Now, if Entity A was to interact twice in Maturity 1, I would want the size to remain same, but the number of interactions to increase. With the way it is currently structured, because Entity A is repeated, the interaction now increases by one, but so does the size of the entity (from 31 to 43).
Is there a way to have Excel ignore the value in the SizeofEntity if the Entity name is repeated in another column, or is there another way to make this possible?
The data provided in the images is a small example. I am dealing with a much larger dataset with over 300 different names with hundreds of interactions per maturity period.
I've achieved your expected results using the following logic.
Create a column called EntityConcat on column E. With this you can detect if you have duplicate entity and maturity pairs.
I've concatented them using this formula then dragged down:
=A2&B2
In another column (F) detect if they repeat and only flag the first occurence:
=IF(COUNTIF(E$2:E2,E2)=1,1,"")
Finaly I've created another column that shows sizes for the first occurence only:
=IF(F2=1,D2,0)
Now on your pivot table you can count "SizeofEntity" for total number of occurences but should instead sum this last column's values, where no duplicate entity sizes will be found.
Hope this is what you were after.

Resources