Second largest value in a list that includes equal numbers - excel

I have the following Excel spreadsheet:
A
1 20
2 15
3 20
4 18
5 14
As you can see the values can appear more than one time (e.g. 20) in the list. Therefore, I use the following formula to get the largest value:
={INDEX(A:A,MATCH(LARGE(A1:A99-ROWS(A1:A99)/9^9,ROWS(A1)),A1:A99-ROWS(A1:A99)/9^9;0))}
This formula works perfectly. However, what I want to achieve now is to filter the SECOND largets value out of the list with this formula (in this case 18).
Do you have any idea what I need to change in the formula to get the second largest value from the list?

The LARGE function can be overloaded to find the 2nd largest number.
I have to be honset that I don't understand why you wrote such a complicated formula to find the largest number, but, if you want to find the 2nd largest,
try using LARGE like this:
=LARGE(A:A;COUNTIF(A:A;MAX(A:A))+1)

Related

Why does my =MATCH formula give #N/A or the correct answer in the exact same circumstance?

I'm trying to find the column number using a =match formula. In particular I am looking for a result of 42. As you can see, the formula looking in row 16 finds the number 24 in the 42nd row, and gives this result. However, the formula looking in row 17 does not.
The data is all in number format, and I have done equal checks to ensure 24 does indeed equal the value in both AQ16 and AQ17. Finally, AQ16 and AQ17 are also equal.
Both arrays are also able to find all the data correct (i.e. produce an array which includes the number 24 in the 42nd entry). Despite this, the formula in row 17 does not find 24 in the array, even though it is present.

Average of the smallest 3 values results in Err539

Given a set of values, I want to get the average of the 3 smallest values in one formula.
To do this, I found a similiar recipe for the 3 biggest values on https://exceljet.net/formula/average-top-3-scores
=AVERAGE(LARGE(range,{1,2,3}))
But I'am not able to get this work (doesn't matter if I use SMALL or LARGE).
Here is an example:
By the way, this is LibreOffice Calc but I hope that it behaves like Excel.
If I enter this formula, Calc changes it to =AVERAGE(SMALL(A1:A6;{1,20,3})) (2 has changed to 20).
Even if I change the function type to Array it doesn't work:
What I'am not want is to use auxiliary cells to calc the first, second and third smallest value and averging over this 3 cells.

Date time diff in Excel

I would like assistance in calculating the difference of date and time between each of cells 1 through 15 in hours and minutes.
The problem is the ref is not the same for all so, when the ref changes from R001 to R002, the formula should start calculating the date time difference from the first cell, with the new reference to the last cell with the same ref.
This solution will use AGGREGATE, INDEX and optionally MINUTE functions built into excel
Step 1
Build a list of unique ref IDs and place them in column D
Step 2
Use AGGREGATE to determine the LAST row that a ref ID occurs in.
AGGREGATE(16,6,ROW($A$2:$A$16)/--($C$2:$C$16=D2),1)
AGGREGATE is a function that performs array like calculations. As such avoid using full column references within the function.
16 tells AGGREGATE to use the LARGE formula, so it will built a list in Descending order.
6 tells AGGREGATE to ignore/exclude any results in the list that are an error.
ROW() is going to pull the row number that is being evalutated.
-- will turn the resulting TRUE or FALSE result into 1 or 0.
C2:C16=D2 is looking to to see if the row has the REF ID .
1 tells AGGREGATE to return the 1st number in the list.
Step 3
Rinse, wash, repeat. Determine the FIRST row that a ref ID occurs in.
Again use aggregate just as before. Except this time instead of LARGE, we want to find SMALL so change the 16 to a 15. This will return the row number of the first occurrence of the REF ID.
AGGREGATE(15,6,ROW($A$2:$A$16)/--($C$2:$C$16=D2),1)
Step 4
Now that you know the ROW# to use, place the row number in an INDEX formula to get the cell you want to use. Note that index actually returns the cell address so can be used just like a cell reference.
First Time Refence
INDEX(B:B,AGGREGATE(16,6,ROW($A$2:$A$16)/--($C$2:$C$16=D2),1))
Last Time Reference
INDEX(B:B,AGGREGATE(15,6,ROW($A$2:$A$16)/--($C$2:$C$16=D2),1))
Step 5
Take the difference between the Last and First
INDEX(B:B,AGGREGATE(15,6,ROW($A$2:$A$16)/--($C$2:$C$16=D2),1))-INDEX(B:B,AGGREGATE(16,6,ROW($A$2:$A$16)/--($C$2:$C$16=D2),1))
Now if the first reference occurs before the time stamp of the last referenec you will wind up with a negative number. IF YOU DO NOT CARE ABOUT THE NEGATIVE NUMBER, wrap the whole thing in an absolute function or square the results then square root the results.
ABS(INDEX(B:B,AGGREGATE(15,6,ROW($A$2:$A$16)/--($C$2:$C$16=D2),1))-INDEX(B:B,AGGREGATE(16,6,ROW($A$2:$A$16)/--($C$2:$C$16=D2),1)))
Place your choice of the above formula in E2 and copy down as required.
Step 6
Since you want your answer in JUST hours and minutes, I opted to break the information into two separate columns so you could use them as needed. Also I will be referencing the values in column E instead of embedding them into the following formulas which is also an option if you want to avoid extra columns.
If you format the results in E2 as general you will note you get an integer and some decimal values. The integer represents the number of days. The decimals represent TIME as fraction of a day. In order to get the number of hours, you multiply by 24, since there are 24 hours in a day, and take just the integer. Place the following formula in F2 and copy down.
INT(24*E2)
Since you also want the minutes we can pull those directly from E2 using the MINUTE function. Place the following in G2 and copy down.
MINUTE(E2)

Build proper sum formula in excel

I am trying to figure out how excel can fill down a column if i make a function like sum(A1:A2), sum(A1:A3) and so on. i have had no luck thus far with successfully filling as what would occur is the following result for the respective cells; sum(A1:A2), sum(A2:A3). I am sure there is a very simple fix but I am not typically an excel user.
While it may be tempting to enter the simple formula =SUM(A$2:A2) into B2 and copy it down, if you're going to sum large ranges this is actually incredibly inefficient on large ranges compared to the formula =SUM(B1,A2)
Why? Let's say you copy =SUM(A$2:A2) down 10 rows.
Your result at row 2 only had to sum 1 number: the number in A2.
Your result at row 3 has to sum 2 numbers: the numbers in A2:A3.
Your result at row 4 has to sum 3 numbers: the numbers in A2:A4.
...
Your result at row 11 has to sum 10 numbers: the numbers in A2:A11.
So how many numbers did Excel have to add in total to produce the answers you calculated in B2:B11?
1+2+3+4+5+6+7+8+9+10 = 55
But if we're using the other approach i.e. =SUM(B1,A2) then all we're doing for each row is adding the number to the left to the previously calculated sum above. So on each row, we sum only two numbers together. Meaning to produce the same 10 answers, the amount of numbers that Excel has to add to produce the exact same totals in B2:B11 are:
2+2+2+2+2+2+2+2+2+2 = 20
Now let's extrapolate that, to some sizeable ranges.
Yikes! So how much does this matter in the real world, given we've all got pretty fast computers good at math?
If you fill rows A2:A100000 with some numbers and then put =SUM(B1,A2) in B2 and fill down, it takes well under a second to calculate on my PC. But if you put =SUM(A$2:A2) instead, it takes almost a minute.
My advice: Get out of the habit of using =SUM(A$2:A2). One day you'll thank me for it.

how to convert series of numbers into 0 to 10 range

I have a large series of numbers that I want to convert to a 0 to 10 scale.
I used the following formula to convert the maximum value to 10 and minimum value to 0,
=IF(A1="-","0",MIN(MAX((A1-MIN(A:A))/((MAX(A:A)-MIN(A:A))/11),0),10))
However,I face some problems converting the series where maximum value should be 0 and minimum value should be 10. For example, if column A has the values,
1
4
6
7
8
then 8 should have a value of 0 and 1 should have a value of 10.
Thanks!
Just use the formula =10-B1, where B1 is the cell containing your mentioned formula.
Please note though that your formula has the following flaws:
It is wrong. If you test it with the three numbers 1,2,3 you get 5.5 for the value corresponding to 2. Obviously the correct answer should be 5. This error is caused by the number 11 that you use to divide the (MAX(A:A)-MIN(A:A)). Change it to 10 and everything will work!
It returns #DIV/0! if you have only one number in column A.
It is inefficient because it calls time-expensive functions MAX(A:A) and MIN(A:A) in each and every cell containing this formula. Since these two functions are not dependent on the formula-containing cell, consider using them only once in some other cells and subsequently modify your formula so it contains links to these external cells rather than the functions themselves.
It is hardly maintainable and/or readable. It took me a while to understand how your formula works. Consider separating it into meaningful pieces, place the pieces into separate cells and finally simply link the pieces together in some final - and much smaller - formula.
It is unnecessarily convoluted. There is a much easier formula to achieve the same thing, based on the following:
= 10*B1/C1,
where B1 contains the "distance from minimum", i.e. A1-MIN(A:A), and C1 contains the total length of your range of numbers, i.e. MAX(A:A)-MIN(A:A)

Resources