How do I reference the three largest values in a column and their corresponding text in the column next to it? - excel

I am building an excel sheet that returns the three highest values from a column in another sheet (sheet2, column B) along with their corresponding company (sheet2, column a). Ultimately, in sheet 1, I want to have a table that will display the company with those values.
This is what I am trying to achieve:
AWS ($280.9m), Google ($241.9m), Meta ($168.7m)
I was trying to use the large formula, but this does not help me with referencing the corresponding company so I’m unsure how to return both.

You can use LARGE to get your top-n, and then wrap with INDEX/MATCH and OFFSET to get the company name.
Cell E3 formula:
=LARGE($B$2:$B$7,ROW(E1))
Cell D3 formula, which returns the column to the left of the Large value:
=OFFSET(INDEX($B$2:$B$7,MATCH(LARGE($B$2:$B$7,ROW(D1)),$B$2:$B$7,0)),,-1)
or remove offset and use....
=INDEX($A$2:$A$7,MATCH(LARGE($B$2:$B$7,ROW(D1)),$B$2:$B$7,0))
Drag down your formulas as far as you would like.

The above solution is good but kinda oldschool. I would use =SORT() function instead:
=INDEX(SORT(A46:B56;2;-1);{1;2;3})
Translation to human language:
=INDEX(SORT(MyArray;ColumnToSortBy;Descending);{get first three rows}, [column])
*note: depending on your windows settings your Array row separator may differ. The easiest way to check your it is to select any range with more than one row, then get to formula bar and click F9 to see result preview.
where [column] is an optional argument, by default it takes 1st column.

Related

Pre-selected dependable lists in Excel

Excel coding gurus, i'd like someone to land me a hand in a following problem:
What I have:
I have an Excel 2019. Not the 365 edition.
And I have an Excel table with 2 columns. Column I contains list of people. And each person in the I column has the country of his/her origin denoted in the correspondent cell of H column.
For a better view check this picture, plz.
And I have two drop-down enabled cells (K4 and L4).
K4 holds the list of all countries, presented in H col.
And L4 is supposed to have a list of people, avaliable in the col I
Now, the question is:
How can I code those K4 and L4 cells, so that when in K4 cell I select a country, then in the drop down list of L4 cell I'd get the list of only those people from the I column that have their country of origin equal to the one in K4?
I feel like it is possible to be done with those array-returning functions but I just can't wrap my head around it all.
I have it working like this so far.
The functions necessary for this are INDEX, MATCH, IF, IFERROR, and COUNTIF, which are all available in Excel 2019.
The only thing I'm struggling with (without 365) is that I can't figure out how to remove the white space for the dynamic range.
The formula in column 'E' is to make a unique list of the 'Country' column:
=IFERROR(INDEX($H$2:$H$20,MATCH(0,COUNTIF($E$1:$E1,$H$2:$H$20),0)),"")
This formula must begin at least in row 2, as it needs an empty space above it.
Column F is a similarly unique list of column I, but is dynamic based on the value in K4: *Now updated, see edit below
=IFERROR(INDEX($I$2:$I$20,MATCH(0,IF($K$4=$H$2:$H$20,COUNTIF($F$1:$F1,$I$2:$I$20),""),0)),"")
The validation in K4 is based on column E, and the validation in L4 is based on column F.
As I said, without O365 I can't figure out how to remove the white space, but this should at least work for you.
EDIT: I have had another look at this and figured out the whitespace issue:
Data validation for L4:
=INDIRECT("F2:"&"F"&(COUNTA(F:F)-COUNTIF(F:F," ")+1))
As a bonus, the data validation for K4 can be similar, in case you want to expand column H to include more entries:
=INDIRECT("E2:"&"E"&(COUNTA(E:E)-COUNTIF(E:E," ")+1))
This creates a list from F2 (which will always be our first value) and will expand dynamically as far down as column F has data, given that we change the formula in F2 to be:
=IFERROR(INDEX($I$2:$I$20,MATCH(0,IF($K$4=$H$2:$H$20,COUNTIF($F$1:$F1,$I$2:$I$20),""),0))," ")
Note that the character in the IFERROR of this formula and the COUNTIF of the previous is not a space, it's the character from Alt+255.
As a final nicety, adding some conditional formatting to cell L4 will make it so that selecting data in L4, and then changing the value of K4 (so that L4 is no longer valid) will return whitespace - which is really white text on a white background.
Conditional format formula for L4:
=NOT(IFERROR(ISNUMBER(SEARCH($L$4,TEXTJOIN(" ",1,F:F))),FALSE))
The following is my elaboration on #RGilchrist's answer that he presented above. His was the main idea thus all the credit goes to him too.
The functions, needed for this are INDEX, MATCH, IF, IFERROR, and COUNTIF, which are all available in Excel 2019.
The formula in column 'E' is to make a unique list of the 'Country' column:
=IFERROR(INDEX($H$2:$H$17;MATCH(0;COUNTIF($E$1:$E1;$H$2:$H$17);0));"")
For example, on the pic you can see a formula of the cell E2.
Some comments on this formula:
it should be entered into the cell by Ctrl+Shift+Enter as it is an array formula. And you can see that it is wrapped into curly brackets {}.
the formula needs to have at least 1 cell above it. In this case it is E1.
As you see on the picture - I've deliberately made my dataset sparce, not dence (it has empty rows). To work around having zero in the resultset one has to place 0 to the E1 cell.
on the picture my dataset is colored. That hints the fact that I've announced the dataset as a table. This would allow for some neat features like auto extending of the table should I add more rows to it. And that provides for some functionally neat addressing of the column in the dataset. In my locale the table-addressed following formula would be this:
=IFERROR(INDEX(Tab_1[Стовпець1];MATCH(0;COUNTIF($E$1:$E2;Tab_1[Стовпець1]);0));"") where Tab_1 is the name of the table I've announced. And [Стовпець1] is a name of the column in the table.
Column F is a similarly unique list of column I, but is dynamic based on the value in K4: =IFERROR(INDEX($I$2:$I$20,MATCH(0,IF($K$4=$H$2:$H$20,COUNTIF($F$1:$F1,$I$2:$I$20),""),0)),"")
All comments to previous formula are applicable to this one as well.
The data validation in K4 is based on column E, and the validation in L4 is based on column F. But in order to overcome empty space problem in resulting dropdown list the data validation should be based on a formula that uses OFFSET function.
So the data validation source for K4 would be
=OFFSET($E$2;;;COUNTIF($E$2:$E$10;"?*"))
The relevant screenshot is in my locale but the general interface should be familiar.

Incremental method to change the cells ID (Name)

I'm trying to setup an excel sheet with different columns and in every column I need the single cells to have a specific ID so I can reach to those by code, the simpler one was to put for ex. "column name1" and incremental from there, do you know a method to make something like that instead of changing all the cells ID by hand?
enter image description here
Like this one for example, but intead of having 'feature1' 'feature2' ecc written as text I need those in the cells IDs/Names
EDIT
example of table
Here I want to use a formula to automatically change the name of the table from "A26" to "step1", I tried to use command ="step"&ROW(A26) but this only change the text of the cell instead of the name
Although I have shared above what ROW Function, does, still for a proper explanation I am sharing here
The ROW function returns the row number for a reference.
In our query, ROW(J26) returns 26, since J26 is the twenty sixth row of the column J in the spreadsheet. When no reference is provided, ROW returns the row number of the cell which contains the formula. So in the above query ROW() returns 26 which on subtracting with 25 shall give us 1 which is required.
ROW function takes just one argument, called reference, which may be empty, a cell reference, or a range.
So the formula used in cell J26
=J$25&ROW()-25
And Fill Down and for the rest just press CTRL R and fill down!

Excel: Extract data from well beneath unique identifier

I have a spreadsheet full of data (simplified example below) that I would like to extract the number in the well underneath of "Gimme the number" and paste it into a new column on a separate sheet (i.e. if "Gimme the number" is in G6, I would like to retrieve the value for G7). I do not have access to Excel VBA and have not used macros in the past. I found some examples linked below, but, from what I understand, they would return "Gimme the number", or "Gimme" not 19, 20, and 21. I am not sure if a pivot table is appropriate, because I only want information from a single column. I will only have up to 11 values to extract at any given time, so I think a formula would do it. I am just having a hard time coming up with one that works. Any help would be greatly appreciated!
Search for a text string and return multiple adjacent values
Return multiple matches with wildcard vlookup
I am not sure I get the question well, but I try.
First add a column right of the column with "Gimme..." values. Name it e.g. "Next_value" in the first row. Put in the formula referencing previous column next row. If "Gimme..." is in the cell (for instance) E6, than your formula in the cell F6 is =E7. Copy that formula into the whole Next_value column.
Than select area of these two columns (Label, Next_value) and apply the filter from the Data toolbar. Use the small buttons with triangles at the top of the column Label to adjust the filter so only "Gimme..." rows are filtered.
Now, copy values of Next_value column where you like. If you want just the references, use Paste special function from the Home toolbar and click Paste link button.

How to program excel with vlookup function

I have this excel file with two sheets. Sheet 1 is the page where all of the part numbers and descriptions are placed. Sheet 2 is a database set into two columns one with part numbers the other with the description.
I have been looking into vlookup within excel and in which case i have it working with the part numbers so when i enter the part number or choose from drop down it will auto populate the description for me. The issue I am having now is that when i enter the part number it doesn't auto populate the description column until i double click the cell with the formula and hit enter.
I also want to do a reverse lookup from the description side where it will auto populate the part number as well.
Here is my formula I used for the vslookup.
=VLOOKUP(A9,Database!$A$1:$B$250,2,FALSE)
I came up with this formula after researching how to do it but I had to change the A9 portion to each row number ie. row 9, row 10, etc..
If you want to do a reverse lookup then vlookup will not work as it only works left to right - unless you repeat the data in column A in column C...
However, the more elegant solution is with index() and match().
=INDEX(Database!$A$1:$A$250,MATCH(B9,Database!$B$1:$B$250,0))
Not tested, written based on the info you gave in your vlookup, match will find the position of the item looked for and then index collects the result at that position in column A.
The beauty of index/match is that the columns don't have to be next to each other AS LONG AS THEY ARE THE SAME LENGTH...
Try right clicking the numbers column > format cells > format as text (by choosing "text" under the categories box). Hopefully this will make the auto populate work.

Is there a formula that will paste the result of a separate formula as a value?

Ex.
column A is a formula that outputs an 8 digit ID from a prior delimited calculation. I want to vlookup that ID to a separate set of data, but it is not finding the ID when the lookup value is part of a formula.
Is there a way to paste the formula result as a value in column b?
I have a list of 3000+ IDs, so using the F2, F9 trick won't work, since I would have to do that cell by cell.
Would prefer not to use VBA, but if that is the only way, can someone help simplify that process (new to using VBA)
If you have data in column A based on a left function of a bunch of numbers, and just want that result in column B, all you have to do is put:
=Value(ColRow)
in Column B. Then you can look up the value in Column B via VLookUp.
I am an avid Excel user and personally tested this solution. Though it appears #Scott beat me to it in the comment section.

Resources