How to find the maximum value based on another column? - excel

I am trying to find the maximum value based on another column. This is what I have tried.
=MAX(IF(Sheet3!$B$2:$B$5491=Sheet4!A3,Sheet3!$E$2:$E$5491))
How I am reading this code is that if the criteria in sheet 3 in column B is equivalent to the cell in A3 in sheet 4, then return the maximum value that would be in column E from sheet 3. I found this code online and have tried variations but all it is doing is returning 0. Is there another way I could go about finding the max value?
Thanks,
GCC

It's an Array formula (aka CSE formula). After entering or editing it, you should press
CtrlShiftEnter
otherwise it won't work. Always remember this for array formulas.

Related

Get list of rows with a second non-blank value and the column header for the second non-blank occurrence

I have an Excel sheet with data represented as below:
I need to get all the sites with a second non-blank column in the site's row (except Site, of course) and also get the Column Header value.
In the example, sites B, F and G have a second Y. So the result should be:
I am not very well versed with Excel Formulas, but I have experimented a bit with INDEX and I can find the second non-blank value itself. But I can't figure out a way to return the result I require.
Using the below formula I get as far as this, but still nowhere near my expected result.
{=INDEX(B2:I2,SMALL(IF(B2:I2<>"",COLUMN(B2:I2)-COLUMN(B2)+1),2))}
Edit:
With #Harun24HR 's answer I get this new result.
Try below formula.
=INDEX($B$1:$I$1,,SMALL(IF(($B$2:$I$11="Y")*($A$2:$A$11=C14)>0,COLUMN($B$2:$I$11),""),2)-1)
May need array entry with CTRL+SHIFT+ENTER.
Edit#: As per my below screenshot I have used below formulas.
For result column in J2 cell put
=IF(COUNTIF(B2:I2,"<>")>1,ROW(),"")
In C14 put
=IFERROR(INDEX($A$1:$A$11,SMALL($J$1:$J$11,ROW(1:1))),"")
And in D14 cell put below formula.
=INDEX($A$1:$I$1,MAX(($B$2:$I$11<>"")*($A$2:$A$11=C14)*(COLUMN($B$2:$I$11))))
Please note. You no need to array entry for these formulas.
Finally I ended up solving this using a combination of the accepted answer (by #Harun24HR) and How To Extract A Dynamic List From A Data Range Based On A Criteria Without Filters In Excel
In J2 through J11, I added the formula:
{=IFERROR(INDEX($B$1:$I$1,,SMALL(IF(($B$2:$I$11<>"")*($A$2:$A$11=A2)>0,COLUMN($B$2:$I$11),""),2)-1), "")}
In A15 to A24 (same number of rows as the original range), I added the formula:
{=IFERROR(INDEX($A$2:$A$11,SMALL(IF($J$2:$J$11<>"",ROW($A$2:$A$11)),ROW(1:1))-1,1),"")}
In B15 to B24, it's a simple VLOOKUP:
=IFERROR(VLOOKUP(A15,$A$2:$J$11,10,0),"")
This way, the result table is dynamic.

Dynamic list, excel formula

I'm going crazy over this, trying to figure out how to make a dynamic array to create a smaller list from a bigger list based on a criteria. All of it needs to be dynamic because the base list will change. Have googled for two days but can't find the proper solution.
I'm a rookie creating these things. Have tried below but it doesn't work:
=IFERROR(INDEX('2.Data'!$L$3:$L$300;SMALL(IF('2.Data'!$L$3:$L$300="12378";ROW('2.Data'!$L$3:$L$300)-ROW('2.Data'!$L$3)+1);ROWS(B$2:B2)));"")
Example:
Column A
1. 12345
2. 12345
3. 12378
4. 12345
5. 12378
6. 12345
Column B (result)
1. 12378
2. 12378
Column B should have a fancy formula that gets value from column A based on criteria=ends with 78, presented without empty cells between values.
With data in column A, in B1 enter the array formula:
=IFERROR(INDEX($A$1:$A$26,SMALL(IF(RIGHT($A$1:$A$26,2)="78",ROW($A$1:$A$26)),ROW(1:1))),"")
(your version of Excel may require the ; rather than the , in the formula) and copy downward:
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key. If this is done correctly, the formula will appear with curly braces around it in the Formula Bar.
You can avoid the array formulas if you use a "helper" column.

Excel find closest bigger value in a column to a given lookup value

I am going to input data in A2:A100. Based on a formula, a calculation is made and returns results in J2:J100. The lookup value is in cell P2. There are cells in column J that are currently displaying "#DIV/0!", due to the fact that there are cells in column A that have not been filled yet.
I am trying to find the closest bigger value in A2:A100, using as lookup value P2. I input in Q2 the following array formula (ctrl+shift+enter): =LARGE(J2:J100;COUNTIF(J2:J100;">"&$P$2)) This formula returns "#DIV/0!". I assume that cells in column J that are currently displaying "#DIV/0!" are the cause of the problem.
Could anyone please help me to get excel to ignore these cells in column J and find the closest bigger value in regards to the lookup value in P2? Thank you in advance!
You should be able to do it with AGGREGATE, using the option to ignore error values
=AGGREGATE(14,6,J2:J100,COUNTIF(J2:J100,">"&$P$2))

Second Largest Value with criteria in excel

I'm trying to find the second largest value of a given criteria in excel. So the formula I was trying to use was
=LARGE(IF($B$1:$B$216=1,$F$1:$F$216,""),2).
The problem is that it is returning the second largest overall value, but I want the second largest value where column B is 1. Better Answers would be helpful.
You are using an array (CSE) formula and you did not enter it the key combination for array formuas. Edit the cell again and click Ctrl+Shift+Enter.
Or if you want a normal (non CSE) formula, use this:
=AGGREGATE(14,6,$F$1:$F$216/($B$1:$B$216=1),2)

Count occurrences of values in a specific range (Excel) (no VBA)

I need to count all of the occurrences of a given value from a specific range of cells (containing strings or numbers), depending on a parameter stored in another cell.
I prepared a simple Excel table as an example (see attached image): let's say I want to count all of the occurrences of the VALUE "4" for the BASE "100". The result should be: 2 (C4 + C5).
Attached image
I tried to use COUNTIFS and FIND functions but with no results. The former only considers exact values (so the 4 in cell C5 will be ignored) while I seem to be unable to add another condition - the BASE column - to the latter.
Fact is I need to solve this with formulas only, no programming.
Thanks in advance for your help!
Use the SUMPRODUCT:
=SUMPRODUCT(($B$2:$B$10=100)*(ISNUMBER(SEARCH(4,$C$2:$C$10))))
There's a couple of other approaches, the simpler one is just to add another column which identifies matches for you, then have your count just sum the results of that column.
Solution image
So we put the values we want to find in some reference cells, the BASE match goes in G2, and the VALUE we're looking for goes in G3.
In column D we put a formula in D2:
"=IF(B2=$G$2,IF(ISERR(SEARCH($G$3,C2)),0,1),0)"
Returns 0 if the BASE matches and we can find at least one occurent of VALUE
B2=$G$2 - Does the BASE column match the BASE we're looking for
ISERR(SEARCH($G$3,C2)) - Does searching for the VALUE return an error (if it does, we know that VALUE isn't there)
Copy this formula to all the cells in column D, and then you can just use a simple SUM(D:D) to count the occurences where your conditions are met.
The neater but slightly more complex alternative is to use an array formula to do the match finding and counting all in one formula. This would look like this:
"{=SUM(IF(B:B=$G$2,IF(ISERR(SEARCH($G$3,C:C)),0,1)))}"
Pretty much the same as the formulas in column D, but now we use B:B and C:C in place of B2 / C2 etc. and stick the SUM around the whole thing. If you finish editing with Ctrl+Shift+Enter instead of just Enter, that'll make it an array formula.
Microsoft Array Formula Guidelines
NB: this WILL NOT count multiple occurences of 4 in a single VALUE cell.
p.s. Assuming you would want it to actually return 3 in this case (you missed the 4 in C7)

Resources