Excel Multiply one set of values with given matrix and sum results - excel

I need to redistribute values for Old entries by using new distribution in a given table.
Example:
Need to redistribute using given % in this table:
So New Value of Element 1 = 99% * old1 + 7% * old2 + 3% * old3 + 26% * old5
This is not whole table, it is pretty large. There must be a simpler way than adding things up manually.

You can use the MMULT() worksheet function for that.
Example:
A B C D E F
1 Amount
2 100
3 200
4 500
5 400
6
7 Percentages 1 2 3 4
8 99 7 3 26 =MMULT(B8:E8;A$2:A$5)/100
9 1 93 34 0 =MMULT(B9:E9;A$2:A$5)/100
10 0 0 63 74 =MMULT(B10:E10;A$2:A$5)/100
For your information: I've entered the first formula in F8, and dragged and dropped until F10.

Related

Excel, look values in table where both rows and columns are ranges

I apologise if the title is confusing. it's hard for me to summarise this issue in one sentence.
I'm trying to automate some spreadsheets, but sadly using VBA is not an option (most people here get confused by them and end up avoiding those spreadsheets).
The problem: I have rows in one sheet with data for velocity and angle and I'm trying to get a value from this other table based on those parameters.
The issue is that this other table is based in ranges of values for both columns and rows.
A B C D E
1 0 1-30 31-60 61-90
2 0 to 1 10 20 20 30
3 1.1 to 2 10 20 30 30
4 2.1 to 3 20 30 30 40
5 '>3 30 40 40 40
Where column A is velocity range, Row 1 is angle range
So for example if I have a velocity of 1.5 m/s with an angle of 40°, I want to be able to get the result of 30.
My best idea is to create auxiliary or helper columns to indicate which velocity and angle range they belong to and then use a VLOOKUP MATCH combo.
Even though it's a simple solution, I just wanted to know if there is a more elegant solution available that comes to mind or if you think this is already elegant enough.
Thanks.
As Scott mentioned, using ranges as titles makes it difficult.
If you simply put in the minimums instead youcan make the following:
A B C D E F G H
1 0 1 31 61 Velocity 1.5
2 0 10 20 20 30 Angle 40
3 1.1 10 20 30 30 Result 30
4 2.1 20 30 30 40
5 3.1 30 40 40 40
Where H1 and H2 are your input cells.
H3 gives you the result with: =INDEX(B2:E5,MATCH(H1,A2:A5,1),MATCH(H2,B1:E1,1))

Find nearest positive and negative value to 0 within a table of values

I have the following Excel spreadsheet:
A B C D E F G
1 Q1 Q2 Q3 Q4 Nearest negative value to 0 -10
2 Asset 1 -50 85 -90 70 Nearest positive value to 0 5
3 Asset 2 -28 -80 -45 60
4 Asset 3 -30 50 55 -10
5 Asset 4 -20 5 -80 -15
6 Asset 5 35 -30 27 -98
7
In Cells A1:E6 I have different assets with their performance from quarter Q1-Q4. The performance can be positive or negative.
In cell G1 and G2 I want to find the nearest negatvie and positive value to 0 in Cells B2:E6. In this case this would -10 and 5. Therefore, I tried to go with the solution here:
G1 = {MAX(IF($B$2:$E$6<0,1,0)*($B$2:$E$6))}
G2 = {MIN(IF($B$2:$E$6>0,1,0)*($B$2:$E$6))}
However, both formulas give me 0 as a result.
Do you have any idea how to solve this issue?
NOTE: All values in Cells B2:E6 are unique.
For largest negative number
=AGGREGATE(15,6,B2:E6/(B2:E6>0),1)
For smallest positive number
=AGGREGATE(14,6,B2:E6/(B2:E6<0),1)
You do not need the *:
=MAX(IF($B$2:$E$6<0,$B$2:$E$6))
And
=MIN(IF($B$2:$E$6>0,$B$2:$E$6))
These are Array formula and need to be confirmed with Ctrl-Shift-Enter.
Along with the AGGREGATE given by Forward Ed if on has Office 365 Excel:
=MAXIFS($B$2:$E$6,$B$2:$E$6,"<"0)
And
=MINIFS($B$2:$E$6,$B$2:$E$6,">"0)

How to generate random numbers from different intervals that add up to a fixed sum in excel?

I need to generate 13 numbers from 13 different intervals which will add up to 1360. In the chart below, "index" means the index of the 13 different numbers. Mean means the mean (average) of the intervals. The range will be plus or minus 15% of the mean as shown below. I will prefer to have the random numbers generated based on the normal distribution with N(mean, 7.5% of mean). I take it back. No normal distribution. Please use +- 15% as hard limits of the intervals.
It will be great if anyone could figure out how to do it in excel. Algorithms will be appreciated as well.
Index mean 15% low high
A 288 43 245 331
B 50 8 43 58
C 338 51 287 389
D 50 8 43 58
E 16 2 14 18
F 66 10 56 76
G 118 18 100 136
H 17 3 14 20
I 91 14 77 105
J 26 4 22 30
K 117 18 99 135
L 165 25 140 190
M 18 3 15 21
I would sort the table by increasing mean:
and use a column for a helper value (column H above).
The idea is to maintain -- while going to the next row -- the current deviation from a perfect aim for the final target. Perfect would mean that every random value coincides with the mean for that row. If a value is 2 less than the mean, then that 2 will appear in the H column for the next row. The random number generated for that next row will then not aim for the given mean, but for 2 less than the mean. The range for the random number will appropriately be reduced so that the low/high values will never be crossed.
By first sorting the rows, we can be sure that this corrected mean will always fall within the next row's low/high range, and so it will always be possible to generate an acceptable random number there.
The final value will be calculated differently: it will be the remainder that is needed to achieve the target sum. For the same reason as above, this value is guaranteed to be within the low/high range.
The formulas used are as follows:
| F | H
--+--------------------------------------------------+------------------------------
2 | =RANDBETWEEN(D2, E2) |
3 | =RANDBETWEEN(B3+H3-C3+ABS(H3), B3+H3+C3-ABS(H3)) | =SUM($B$2:$B2)-SUM($F$2:$F2)
4 | (copy above formula) | (copy above formula)
...| ... | ...
13 | (copy above formula) | (copy above formula)
14 | =SUM($B$2:$B14)-SUM($F$2:$F13) |
In theory the rows do not need to be sorted first, but then the formulas cannot be copied down like above, but must reference the correct rows. That would make it quite complicated.
If it is absolutely necessary that the rows are presented in order of the Index column (A, B, C...), then use another sheet to do the above. Then in the main sheet read the value into the F column with a VLOOKUP from the other sheet. So in F2 you would have:
=VLOOKUP(A2, OtherSheet!$A$2:$F$14, 6, 0)
Get the random number like this
num = Int ((300 - 200 + 1) * Rnd + 200) //between 200 and 300
Click here for more information
and the random number need to be the total sum minus the sum that you already got and the last one will be that left.
for example: (if we have 4 numbers sum up to 100)
A is a random number between 0 to 100 //lets say 42
then B is a random number between 0 to (100-42) => 0 to 78 //lets say 18
then C is a random number between 0 to (100-42-18) => 0 to 40 //lets say 25
then, in the end D is 100-42-18-25 => D is 15
*100-42-18-25 is the same as 100-Sum(A,B,C)
Here is my example generate random number based on low and high.
The formula in column F is just a RANDBETWEEN:
=RANDBETWEEN($D2,$E2)
Then you can get the result always equal to 1360 with the formula below for column G:
=F2/SUM($F$2:$F$14)*1360
So cell G15 will always be 1360 which is the sum of all those 13 intervals.

Using Excel to allocate values based off their rank while remaining within constraints

I am trying to create a resource calculator that can tell me how many people i need to put on each section depending on the current work waiting and work coming in. Prioritizing sections which have the most work waiting first.
Upper Limit Allocation Prod Ranking
12 [to calc] 28% 1
15 18% 2
5 17% 3
4 8% 4
2 6% 5
3 .2% 6
4 .2% 6
Similar to the other question I have a constraint that i only have so much to allocate. For this example we will use 38 as the amount that is to be allocated.
I have used the formula from the other answer:
=MIN(A2,$E$1-SUMIF($D$2:$D$8,"<"&D2,$B$2:$B$8))
Where E1 contains the total to be allocated.
I have two issues with this formula:
1)The issue that I am having is that I require a minimum value of atleast 1 person in each of these sections.
I have tried using a max function to simply set this value, however this leads to the resources allocated going over the total amount.
What equation would I need to use to make it account for both the total available to allocate, the minimum requirement for each fund and the maximum limit for each fund.
2) It only returns solid integers, would there be a way to retreive more precise results, maybe by changing it to a % distribution?
UL Alloc Rank Capacity Lower Limit
2 1 15 93 1
3 1 15
4 1 15
6 6 8
1 1 15
2 1 15
4 4 9
2 2 7
4 4 4
15 15 2
12 12 10
12 12 1
1 1 11
13 13 5
6 6 6
5 1 15
5 5 3
1 1 14
2 2 13
3 3 12
3 1 15
Reference: Using the Excel's Rank() function to calculate allocations based on ranking and constraints
Simply subtract the 100 on all sides and add them separately:
=MIN(A2-100,($E$1-100*COUNTA($A$2:$A$8))-(SUMIF($D$2:$D$8,"<"&D2,$B$2:$B$8)-COUNTIF($D$2:$D$8,"<"&D2)*100))+100
What is returned depends on your entries in Column A and in E1. You can change Column A based on a percentage distribution and the formula will return the corresponding values.
Edit:
If you set your lower threshold into F2, your Constraint into E2, using this formula
=MIN(A2-$F$2,($E$2-$F$2*COUNTA($A$2:$A$8))-(SUMIF($D$2:$D$8,"<"&D2,$B$2:$B$8)-COUNTIF($D$2:$D$8,"<"&D2)*$F$2))+$F$2
the result looks like this:

Excel - running % of running total in pivot table

I have a table like:
periodo quintil pos
201611 1 10
201611 2 20
201611 3 30
201611 4 40
201611 5 50
201612 1 9
201612 2 19
201612 3 29
201612 4 39
201612 5 49
I need to create a pivot table like:
periodo quintil running_pos running_%
201611
1 10 7%
2 30 20%
3 60 40%
4 100 67%
5 150 100%
201612
1 9 6%
2 28 19%
3 57 39%
4 96 66%
5 145 100%
Since the running total is not a new field, but a way to show an older field (pos- show as total in quintil), the problem arises when I try to create the running % of the running total.
How can I introduce also this field (running % of running total)?
In spanish there's nothing with a name like running totals translation....
To display what you want in a Pivot Table
- Drag pos to the values area three times
- For the first, use the SUM
- For the second, use the "show as running total"
- For the third, use the "show as % running total"
Here are the results with minimal formatting
Here are the value settings for the third column:

Resources