Split a percentage over 3 fields? - excel

I've got 3 cells in my spreadsheet that have the layout as below. These values are dynamic, however what I need to do is split a percentage over the 3 fields, and then increase the number.
Total Staff Costs £1,000.00
Total Hardware Costs £0.00
Total Expenses £400.00
For instance, the above comes to a total of £1400, however I need to charge 10% of my own time on top of this so £140.
What I can't just do though, is take this 10% and split it over the 3 fields, ie. I can't just add £46.70 to each field, because no hardware has been bought, so to say its £46.70 would raise some questions. I need to split it proportionally between each one.
How can I go about adding X% to the fields proportionally?

Wouldnt the logic be to determine the percentage of the total for each field. Then multiply that percentage by the total of the 10%
so you have 3 fields totalling 1400
so 1000 / 1400 = .714286
so 0 / 1400 = 0
so 400/ 1400 = .0285714
now multiply these by the totals
so 1400 * .714286
so 1400 * 0
so 1400 * .0285714
These should total to the 10%
so all your data is in Column b in cells 1, 2, 3
The formula that would go in to the cells C1, C2, C3 (assuming you want these totals in the next column over)
=(B1/SUM($B:$B)) * (SUM($B:$B)*0.1) 'Cell C1
=(B2/SUM($B:$B)) * (SUM($B:$B)*0.1) 'Cell C2
=(B3/SUM($B:$B)) * (SUM($B:$B)*0.1) 'Cell C3

Related

PowerPivot Grand Total, Sum of all change in %s?

So I am working on a report that has to show total 'pts' in a table based on the performance of certain groups of work.
Right now I have a PowerPivot that Sums Actuals, Forecasts, and the Variance. Then I have separate formulas that filter on each group so that I get a variance % based on each group.
Example formula - 'Group1 Acc:=ABS(CALCULATE(([Actual]-[Forecast])/[Actual],talbe[name]="Group 1"))'
I want the table to look like this....
Column Group 1 Group 2
Criteria 1 25% 25%
Criteria 3 20% 20%
Criteria 4 10% 10%
Grand Total 21.2% 55%
Group 1 is how it is currently working and makes sense to me but isn't doing what I want. It is getting the weighted % change of all the groups. Total Actual-Total Forecast/Total Forecast basically. In this example it comes out to 21.2% because Criteria 4 had a larger % of the total Actual and Forecast for the time period I am comparing.
I want it to work like it is showing in Group 2. The SUM of the total %s over each criteria group. I've tried SUMX formulas, Value(), and such but can't figure this out. Any help would be appreciated.
Thank you!
Check out this article: Subtotals and Grand Totals That Add Up “Correctly”
Basically, you can create logic so that the total behaves separately from the individual rows. Something along these lines:
Measure =
IF(COUNTROWS(VALUES(Table1[Criteria])) = 1,
[Group 1 Acc],
SUMX(VALUES(Table1[Criteria]), [Group 1 Acc])
)
Data:
Type Actual Forcast
Criteria1 33 32
Criteria2 543 345
Criteria3 643 633
Criteria4 45 65
Criteria5 7890 7999
MEASURE 'datatable'[SumOfActuals] =
SUM ( 'DataTable'[Actual] )
MEASURE 'datatable'[SumOfForcast] =
SUM ( 'DataTable'[Forcast] )
MEASURE 'datatable'[Group1] =
DIVIDE (
'datatable'[SumOfActuals],
CALCULATE ( 'datatable'[SumOfForcast], ALLSELECTED () )
In Excel, filter for Criteria 3 and 4
Row Labels Group1
Criteria3 92.12 %
Criteria4 6.45 %
Grand Total 98.57 %

Best method to calculate provision from a table with provision levels?

I have a table with provision levels.
Sales Provision
0 5%
20 000 22%
100 000 30%
A salesman has 5% provision on the first 20 000, 22% on the next 80 000 and 30% on everything above that.
For example a salesman who sells for 230 000 will have provision
=20 000 * 0,05 + 80 000 * 0,22 + 130 000 * 0,30
How can I express this efficiently with a formula? The formula
Needs to be easy to copy to several rows (where a salesman is described by each row)
Needs to work even if I add more provision levels
Well I can say this works (hopefully) for requirement #2:
Needs to work even if I add more provision levels
But note that I am unsure about requirement #1:
Needs to be easy to copy to several rows (where a salesman is described by each row)
Anyway, with this data:
A B C D E
------------------------------------------
0 0.05 Value 230000
20000 0.22 Total Provision 57600
100000 0.3
I used this formula in E2:
=IFERROR(SUMPRODUCT((INDIRECT("A2:A"&MATCH(E1,A:A,1))-INDIRECT("A1:A"&MATCH(E1,A:A,1)-1))*INDIRECT("B1:B"&MATCH(E1,A:A,1)-1))+(E1-INDEX(A:A,MATCH(E1,A:A,1)))*INDEX(B:B,MATCH(E1,A:A,1)),E1*B1)
If we break this formula down:
The first basic step is to find the index at which the sale value resides. This is the first lower value compared to the sale value. In your example data this is straight forward because the index is the last in the provision list. However to accommodate sale values that fall within the list range we can use:
MATCH(E1,A:A,1)
where E1 is the sale value and A:A is the sale-provision list.
Using this we can incorporate an INDIRECT to get the desired range we need to work with. In this case A1 to A & Index:
INDIRECT("A1:A"&MATCH(E1,A:A,1))
But even within this range we need to figure out two distinct values:
The provision value index lower than our sale value (i.e. 20 000 * 0.05 + 80 000 * 0.22)
The rest of the provision sale value (i.e. 130 000 * 0.30)
So to get the first value we need to set up an array like this:
(20000 - 0) * 0.05 = 20000*.05 = 1000
(100000 - 20000) * 0.22 = 80000*.22 = 17600
SUM = 18600
That can be done by using
(A2:A3 - A1:A2)*(B1:B2)
But to put that in our INDIRECT formula, that would look like
INDIRECT("A2:A"&MATCH(E1,A:A,1)) <- A2:A3
INDIRECT("A1:A"&MATCH(E1,A:A,1)-1) <- A1:A2
INDIRECT("B1:B"&MATCH(E1,A:A,1)-1) <- B1:B2
(INDIRECT("A2:A"&MATCH(E1,A:A,1))-INDIRECT("A1:A"&MATCH(E1,A:A,1)-1))*INDIRECT("B1:B"&MATCH(E1,A:A,1)-1))
Just surround that with a SUMPRODUCT to get the total:
SUMPRODUCT((INDIRECT("A2:A"&MATCH(E1,A:A,1))-INDIRECT("A1:A"&MATCH(E1,A:A,1)-1))*INDIRECT("B1:B"&MATCH(E1,A:A,1)-1))
Then the second value is just the total sale value subtracted by our index value and multiplied by the corresponding provision rate. So that would be:
(E1-A3)*B3
We actually don't need INDIRECT here, a couple INDEX - MATCH lookups will do:
E1 <- E1
INDEX(A:A,MATCH(E1,A:A,1)) <- A3
INDEX(B:B,MATCH(E1,A:A,1)) <- B3
(E1-INDEX(A:A,MATCH(E1,A:A,1)))*INDEX(B:B,MATCH(E1,A:A,1))
Then adding those to formulas together results in the derived formula I showed earlier.
The final addition however was to add an IFERROR wrapper because if the value is less than the first non-zero provision the INDEX-MATCH and INDIRECT will fail. So in the case of an error that means we just need to multiply the sale value by the first provision rate:
E1*B1
And of course if you add an additional provision row:
A B C D E
------------------------------------------
0 0.05 Value 230000
20000 0.22 Total Provision 63600
100000 0.30
200000 0.50
Or change the provision:
A B C D E
------------------------------------------
0 0.05 Value 22000
20000 0.22 Total Provision 1440
100000 0.30
The formula will index to the proper provision and calculate it properly.
Also,
Since I know I use commas and decimals in my locale and I realized you don't here is the formula for semi-colon list separator:
=IFERROR(SUMPRODUCT((INDIRECT("A2:A"&MATCH(E1;A:A;1))-INDIRECT("A1:A"&MATCH(E1;A:A;1)-1))*INDIRECT("B1:B"&MATCH(E1;A:A;1)-1))+(E1-INDEX(A:A;MATCH(E1;A:A;1)))*INDEX(B:B;MATCH(E1;A:A;1));E1*B1)

Get number of bills from range of dollar amounts - cascading larger to smaller bills

I am building an envelope system where I withdraw a number of bills each pay period and put them into envelopes. What I am trying to do is to determine via formula how many bills of each I need to have. Here is an example:-
My funds would be:
Kids $ 10
Car $ 50
Gas $100
Groceries $225
Gifts $ 40
---------------
Total: $425
What I want is a base formula to extract the number of bills of each of: $1, $5, $10, $20 and $50
How to extract numbers of $50s from this list which should give me 7 [1 Car, 2 Gas, 4 Groceries]?
Ultimate goal should be this:
0 $ 1 bills $ 0
1 $ 5 bills $ 5
1 $10 bills $ 10
3 $20 bills $ 60
7 $50 bills $350
--------------------
Total Cash: $425
UNTESTED. With Kids in A2 and 50,20,10,5,1 in C1:G1 then perhaps in C2 and copied across and down:
=INT(MIN($B2,$B2-SUMPRODUCT($B$1:B$1*$B2:B2))/C$1)
The results might then be summed by column (excluding the labels) to get the count by denomination and each sum multiplied by the column labels (eg =SUM(C2:C10)*C$1) then the sums summed as a cross-check on the total.
Assuming your table is in range A2:B6, I would use some auxiliary cells on its right, like this:
| A | B | C | D | E | F | G |
50 20 10 5 1
Kids 10 0 0 1 0 0
Car 50 1 0 0 0 0
Gas 100 2 0 0 0 0
Groceries 225 4 1 0 1 0
Gifts 40 0 2 0 0 0
These are the formulas in row 2:
C2: =ROUNDDOWN(B2/C$1,0)
D2: =ROUNDDOWN((B2-C2*C$1)/D$1,0)
E2: =ROUNDDOWN((B2-C2*C$1-D2*D$1)/E$1,0)
F2: =ROUNDDOWN((B2-C2*C$1-D2*D$1-E2*E$1)/F$1,0)
G2: =ROUNDDOWN((B2-C2*C$1-D2*D$1-E2*E$1-F2*F$1)/G$1,0)
These formulas could be a bit simpler if you use more auxiliary columns with intermediate results.
Then just copy them to the rows below. Finally, you get the results using a simple SUM per auxiliary bill column, placing them as you like and multiplying those results by the bill value in another column.
One possible way to do this would be to implement the following algorithm:
As in your example we have (a,b,c,d,e,f)=(10,50,100,225,40) as our set of values. For each value run =ROUNDDOWN(a/50,0),=ROUNDDOWN(b/50,0), and so on in a column adjacent to your column of values.
Next, multiply these values by the divisor (in this case 50) and subtract this from the initial amount.
Now run this again in a loop for 10, 5, and 1. That is, run this over the array of divisors (50,10,5,1). You will need three columns for each divisor value, one for the initial use of =ROUNDDOWN(), one for the multiplication, and one for the subtraction. In total then you'll need 12 columns of information.
There is probably a way to implement this in VBA that will cut it down to the three columns of counts you need for each bill type with ease.

Excel VBA Indicator Function for Macro

Suppose I have the following Data
Name Date Notional
Alice 10/1/2006& 1000
Bob 12/5/2011 5000
Dawn 1/1/2010 400
Alice 5/6/2009 500
Alice 7/13/2012 1500
Dawn 4/5/2012 100
I want to add two more columns, Total and Percentage. Where Total sums Notional per person and Percentage looks at a given Notional as a percentage of Total.
So Alice has three trades on three dates with three notionals of 1000, 500, and 1500. Her Total would be 3000 and her three percentages would be 33%, 16.6% and 50%
So my final result would be:
Name Date Notional Total Percentage
Alice 10/1/2006 1000 3000 33%
Bob 12/5/2011 5000 5000 100%
Dawn 1/1/2010 400 500 80%
Alice 5/6/2009 500 3000 16.67%
Alice 7/13/2012 1500 3000 50%
Dawn 4/5/2012 100 500 20%
I am hoping to write a Macro that adds an Sums the Notional for everyone provided the Name matches.
So my cell D2 will be C2 * Indicator(A2,A2) + C3 * Indicator(A3,A2) + C4*Indicator(A4,A2) + C5*Indicator(A5,A2) + C6*Indicator(A6=A2) + C7*Indicator(A7=A2)
Where Indicator(Ak,A2) is an indicator function which takes the value 1 when Range("Ak").Value=Range("A2").Value and zero otherwise.
Is there such a function? I suppose I can create one myself.
Public Function Indicator(c1 As Range, c2 As Range)
Dim out As Integer
If Range(c1).Value = Range(c2).Value Then
out = 1
Else: out = 0
End If
End Function
I am trying to get this to run inside a bigger code. But right now I am getting a lot of errors. I will update if I can get it to run.
I built a Pivot Table with:
Lines: Name | Date
Values: Notional [SUM] | Notional [% of parent row total]

random number based on probability in Excel

How can I create a random number generator which calculates a random number based on a probability?
For example, I have the following numbers with the probability they will occur starting in cell A1 and B1:
100 5%
75 10%
50 42%
30 30%
15 5%
0 8%
Thus, the formula would "randomly" return the number "15" 5% of all times.
Slightly less overhead:
Make a reference chart of your values, and a running total of probability:
C D E
100 5% 0
75 10% 5%
50 42% 15%
30 30% 57%
15 5% 87%
0 8% 92%
Then lookup a 0-1 random number on this chart. =LOOKUP(RAND(),$E$2:$E$7,$C$2:$C$7)
I generated 5224 numbers and produced this pivot chart of the results. Refreshing caused the percentages to waver a bit around the targets, but all attempts looked good.
Row Labels Count Percentage Target
0 421 8.06% 8%
15 262 5.02% 5%
30 1608 30.78% 30%
50 2160 41.35% 42%
75 490 9.38% 10%
100 283 5.42% 5%
Grand Total 5224 100.00%
Or you could do it with two cells and a long if statement:
=RAND()
=IF(A9<0.05,100,IF(A9<0.15,75, ... 0))...
This functionality comes as part of the analysis toolkit add in. You can find this in Excel options -> add ins -> manage add ins.
You want random number generation, and then pick the 'discrete' distribution. The input into this is the table you provided in your post.
"Discrete
Characterized by a value and the associated probability range. The range
must contain two columns: The left column contains values, and the right
column contains probabilities associated with the value in that row. The sum
of the probabilities must be 1."
jsarma's suggestion is also a good one....
You can use vlookup and randbetween.
You'll want to use randbetween. http://office.microsoft.com/en-us/excel-help/randbetween-HP005209230.aspx
vlookup: http://office.microsoft.com/en-us/excel-help/vlookup-HP005209335.aspx
Fill one column with consecutive numbers ranging from 1-100.
Fill another column with 5 100's, 10 75's, 42 50's, etc...
Now...
=VLOOKUP(RANDBETWEEN(1,100),A1:B100,2)
There's probably a better way to do this, but I tried this and it seems to work.

Resources