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

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)

Related

Finding a formula to compute partial sums for consecutive rows that satisfy a condition

How do I do this is excel. The example is provided below. If we don't sell any products on a specific day I would like to move those hours to the next date.
If you need to compute partial sums of Hours for all the consecutive rows between rows that satisfy the condition that the value Sold is greater than zero, you could do this with an auxiliary column
A B C D
---------------------------------
1 |Hours Sold Sums Solution
2 | 300 30 300 300
3 | 30 0 300 0
4 | 0 0 300 0
5 | 30 0 300 0
6 | 300 50 660 360
7 | 23 0 660 0
8 | 100 25 783 123
Here Sums is defined by a formula for C2
=IF(B2>0,SUM(A2:$A$2),C1)
You can automatically populate the cells below.
This formula puts in a cell a partial sum of Hours up to the current row if Sold is nonzero, otherwise copies the previous partial sum of hours. We need this to subtract this value on the next step.
When you have the column C filled, it is sufficient to put the following formula in D2 and populate the cells below
=IF(ROW(B2)>2,IF(B2>0,C2-C1,0),C2)
This formula handles correctly both D2 that does not have a preceding row with values and the remaining cells in column D.
In fact you could combine the two formulas together and avoid the need to have an auxiliary column. Put the following formula in C2 and spread it down to the rest of the cells in column C
=IF(ROW(B2)>2,IF(B2>0,SUM(A2:$A$2)-SUM(C1:$C$2),0),A2)
to get
A B C
---------------------------------
1 |Hours Sold Solution
2 | 300 30 300
3 | 30 0 0
4 | 0 0 0
5 | 30 0 0
6 | 300 50 360
7 | 23 0 0
8 | 100 25 123

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))

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

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.

How to multiply each row and then sum it with the product in the next row etc

I am trying to calculate total for each month based on Score and Number of occuruencies each month:
Category# Score Jan-18 Feb-18 Mar-18 Apr-18
category1 10 1 5 1 5
category2 8 2 4 2 4
category3 7 3 3 3 3
category4 6 4 0 4 0
category5 5 0 1 0 1
TOTAL 71 108 71 108
In the essence, for January I could type the following formula:
=($B$2*C2)+($B$3*C3)+($B$4*C4)+($B$5*C5)+($B$6*C6)
But it is very clumsy, so I am wondering if I could something more elegant and clean
that is what SUMPRODUCT is for
=SUMPRODUCT($B$2:$B$6,C2:C6)
Use SUMPRODUCT. It's exactly what you need:
SUMPRODUCT function
I replied your data:
The formula I have used is:
=SUMPRODUCT($B$4:$B$8;C4:C8)
After applying to first column (Jan-18), just drag it to the right, and it should return the right values, as you can see in the image.
Hope this helps!

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.

Resources