Mileage log Trouble - excel

I am trying to create a formula that finds the monthly mileage for a vehicle. The simple =max(array)-min(array) will not work because there are blanks/0 cell values due to a vehicle not being driven. This causes the minimum to be zero. I have tried to use the small(array,2) but if there are multiple cells, it counts every blank as a separate value. Is there a simple way to express this? All cells are pulling the mileage from a separate workbook so even the blank cells have a formula. I want to write a formula for the following expression, "the cell with the maximum mileage minus the cell with the minimum mileage but the minimum cell can not be zero or blank, if it is skip/do not use".
I know the maximum for the first box is 40532 - minimum is 40285= 247
The maximum for the second box is 13281 - minimum is 13154= 127

You can use MAXIFS()for this: it calculates a maximum, in case of criteria.
MAXIFS() is described in this URL.
Edit for more explanation
I've just created the following worksheet:
A B C
1: 100 200 300
2: 0 100 300
3: 400 50 200
4: 0 100 100
I have entered this formula:
=MINIFS(A1:C4;A1:C4;">0")
The first A1:C4 is the range, where the minimum should be calculated.
The second A1:C4 is the range, where the criterion should be validated.
">0" is the criterion itself.
The result was 50, as it should be.

Related

Excel - standard deviation where source cells are a count

I have some data that looks like this
Condition 1
Condition 2
Condition 3
Condition 4
Condition 5
0
0
0
70
0
0
50
10
0
0
120
0
0
5
5
Where the value in each cell is the number of meters of an asset that is the given condition. Or in other words, a count of the number of meters that are a '4'.
How do I calculate a standard deviation for this? Obviously the std.dev would be '0' for the first row, higher for row 2, and fairly low for row 3.
Something similar to REPT, but that repeats a value x times in a formula?
I considered a helper column but the number of meters that there are in total makes this impractical.
I am not a math expert, but I can show you how to "make a range of numbers" based on the criteria shown, using Excel 365.
Suppose your data is in the range B2:F4 as shown below. In cell G2, enter the following formula and drag it down:
=STDEV.P(--FILTERXML("<t><s>"&TEXTJOIN("</s><s>",1,REPT($B$1:$F$1&"</s><s>",$B2:$F2))&"</s></t>","//s[number()=.]"))
The above will calculate the standard deviation using the STDEV.P function, but I am unsure if this is the right function to use as there are many other variations to the original STDEV function.
Regardless, the following part of the formula is able to return a range of numbers as desired:
=--FILTERXML("<t><s>"&TEXTJOIN("</s><s>",1,REPT($B$1:$F$1&"</s><s>",$B2:$F2))&"</s></t>","//s[number()=.]")
You can view this question and the answer by JvdV to understand the use of the FILTERXML function.
Another way of doing it is to use the alternative SD formula
which would give you
=SQRT((SUM(A2:E2*COLUMN(A2:E2)^2)-SUM(A2:E2*COLUMN(A2:E2))^2/SUM(A2:E2))/SUM(A2:E2))
for the population standard deviation.
The Excel 365 version using Let is more readable I think:
=LET(x,COLUMN(A2:E2),
mpy,A2:E2,
n,SUM(mpy),
sumxsq,SUM(mpy*x^2),
sumsqx,SUM(mpy*x)^2,
numerator,sumxsq-sumsqx/n,
SQRT(numerator/n)
)
A bit less obviously, you could get it from the original formula
=SQRT(SUM(A2:E2*(COLUMN(A2:E2)-SUM(A2:E2*COLUMN(A2:E2))/SUM(A2:E2))^2/SUM(A2:E2)))
Again, in Excel 365 you could write this as:
=LET(x,COLUMN(A2:E2),
mpy,A2:E2,
n,SUM(mpy),
xbar,SUM(mpy*x/n),
numerator,SUM(mpy*(x-xbar)^2),
SQRT(numerator/n)
)
Change the denominator to
(SUM(A2:E2)-1)
for the sample standard deviation.
I ended up figuring it out.
I added a column which calculated the average. (Say column F)
I then had a formula like this
=SQRT(SUM(A2*POWER((1-F2),2),B2*POWER((2-F2),2),C2*POWER((3-F2),2),D2*POWER((4-F2),2),E2*POWER((5-F2),2))/SUM(A2:E2))
Essentially this calculated the variance from the mean for each condition value, multiplied by the number of values (e.g. number of meters) of asset that are that particular condition, then did the normal other standard deviation calculations (sum, divide by total, square).

Cumulative Sum by Specific quantity up to value

I have a horizontal matrix of values in Excel that I want to be able to show a quantity in a series up to a predetermined total value. If the last value in the series is less than the specified quantity then the value that will satisfy the cumulative sum is the value used. Empty values thereafter.
For example: Max cumulative sum of 200 in 7 units of 30: 30,30,30,30,30,30,20.
Should be straightforward but I've had some trouble doing it. Thanks.
I've tried nested if thens with conditional sums but the formulas seems more less helpful than the basic explanation of what's needed.
I can do most of the function but the nested if thens are too complex and are creating problematic edge cases. Hoping someone has a more concise idea.
You could combine some MOD and INT together, cell A1put this formula and drag it to the right:
=IF(COLUMN()<=200/30,30,IF(COLUMN()=INT(200/30)+1,MOD(200,30),""))
Obviously you can reference these 200 and 30 from an absolute cell address.
Example to add to 308 in steps of 14:
Formula in A1:
=IF(COLUMN()<=$A3/$A4,$A4,IF(COLUMN()=INT($A3/$A4)+1,MOD($A3,$A4),""))
Another example to add to 312 in steps of 14:
You can use Min to determine the value for each cell, and Index to specify the range
Like this (also handle returning blanks for columns past the last value)
=IFERROR(1/(1/MIN($A$2-SUM(INDEX(4:4,1,1):INDEX(4:4,1,COLUMN()-1)),$A$3)),"")

Excel Macro : Find Max repeatedly in column after value=0

I would like to repeatedly calculate the MAX value in a column, after the value in that column = 0 twice in a row. See example:
Torque (Lbf_in)
0
0
.827664554
9.673638344
45.82129669
60.63316727
58.07248688
38.35304642
18.0196209
4.054021835
0
0
...Repeat
We're finding the max torque per cycle of a handle using software that dumps it into excel. the double 0 values show us to reset to cycle the handle again, so we would like to capture the max value again after each double 0 value. The spread sheet has 1,800 cycles, so doing this manually is very time consuming. It's not consistently in the same number of rows that the cycle repeats (its based on time).
Thanks!
If you data is in column A, please enter this formula in cell B4 and drag it to the bottom. =IF(AND(A2=0,A3=0),MAX(OFFSET(A4,0,0,MATCH(0,A4:A700,0),1)),"")
Also make sure to add one 0 at the end of your data.

Adding range in INDEX and RANDBETWEEN

Working formula:
=INDEX({249,749,1999,4999,9999,10000,19999,50000},RANDBETWEEN(1,COUNTA(249,749,1999,4999,9999,10000,19999,50000)))
Amendment needed
249,749,1999,4999,9999,10000,19999,50000 are fixed INDEX and can be easily RANDBETWEEN.
I want to add a range of 500 to 1500 in INDEX and RANDBETWEEN.
Is there any way to include the range of 500 to 1500 in this formula? If not then what is correct way to create a formula as per my needs.
Here is one way.
In an empty column, type your numbers 249,1999,4999,9999,10000,19999,50000. I have removed 749 as it falls in the range 500-1500. Next type 500, 501 and then drag it down to 1500. Let's say you have them in Col A. You can also do this in a separate worksheet.
So if you start at A1 then the values will go up to row 1008 as shown in the image below.
Now use this formula
=INDEX(A1:A1008,RANDBETWEEN(1,1008))
=IF(Randbetween(1,1009)<=1001,randbetween(500,1500),INDEX({249,749,1999,4999,9999,10000,19999,50000},randbetween(1,8)))
A random integer is determined between 1 and the number of possible numbers. if it is less than or equal to the number in the sequential range 500 to 1500, which is 1001, then we tell then we use the randbetween (500,1500). If the initial number if greater than our range, then we have it pull a random number from our supplied list of numbers. 8 is the number of supplied numbers in the static array.
Now if I recall correctly, randbetween is a volatile function. As such anytime something in your work book changes, this formula will recalculate and provide a new number.
UPDATE:
Since you want to limit the 500-1500 range to 35% of the time, try using either of the formulas below:
=IF(Randbetween(1,100)<=35,randbetween(500,1500),INDEX({249,749,1999,4999,9999,10000,19999,50000},randbetween(1,8)))
=IF(Rand()<=0.35,randbetween(500,1500),INDEX({249,749,1999,4999,9999,10000,19999,50000},randbetween(1,8)))

How to nest if and or not Excel

I'm struggling with the following:
I have price ranges from
100 - 200
201 - 300
301 - 400
401 - 500
501 - 600
In every range I give a number from 1-5. I'm trying to give a a number from 1 to 5 to a cell that will check in which price range is.
For example if I write in price field 150 it has to give me to the cell with the formula the number 1 according to the ranges I have. So far I've tried the following but I cannot nest more than 3 ifs.
=IF(AND(B9>=A10,B9<=C10),"1",(IF(AND(B9>=A11,B9<=C11),"2",IF(B9>=A12,B9<=C12,"3"))))
You could use =SUMPRODUCT() to do this. There are also some CSE formulas that would do the trick, but I prefer non-CSE since those can be finicky if someone messes with the formula and doesn't enter them properly:
=SUMPRODUCT((B9>=$A$10:$A$19)*(B9<=B10:B19)*(ROW($A$10:$A$19)-9))
Sumproduct will test each condition here that is then being multiplied together. The conditions in this formula are: (B9>=$A$10:$A$19) and (B9<=B10:B19) which are pretty self explanatory. From each condition, for each row in the range it gets a 1 or 0 (TRUE or FALSE) and then multiplies that by the ROW()-9 for each row being tested. In the end you get the ROW()-9 for whichever row has two TRUE conditions, or 1 * 1 * (Row()-9).
Note that because it tests each row, only one row should return two true conditions, otherwise you'll add up row numbers and get bad results.
Set up a cross-reference table of the minimum amounts for each price range in ascending order. From your sample data this could be Z2:Z7.
        
Your formula to examine the value entered into B9 would be,
=IFERROR(IF(B9<MAX($Z$2:$Z$7), MATCH(B9, $Z$2:$Z$7), NA()), "not in range")
If everything equal-to-and-above 501 should be in price group 5 then simply remove the top values (e.g. 601) and the check for the maximum.
=IFERROR(MATCH(B9, $Z$2:$Z$6), "not in range")
That will still return not in range for values less than 100 but anything over 500 will return price group 5.

Resources