# Excel index match last value

Keep in touch and stay productive with Teams and Officeeven when you're working remotely. These new functions work in any direction and return exact matches by default, making them easier and more convenient to use than their predecessors.

Suppose that you have a list of office location numbers, and you need to know which employees are in each office. The spreadsheet is huge, so you might think it is challenging task. The third argument is the column in that range of cells that contains the value that you seek.

The fourth argument is optional. If you enter TRUE, or leave the argument blank, the function returns an approximate match of the value you specify in the first argument. In other words, leaving the fourth argument blankâ€”or entering TRUEâ€”gives you more flexibility. This example shows you how the function works.

When you enter a value in cell B2 the first argumentVLOOKUP searches the cells in the range C2:E7 2nd argument and returns the closest approximate match from the third column in the range, column E 3rd argument.

The fourth argument is empty, so the function returns an approximate match. If it didn't, you'd have to enter one of the values in columns C or D to get a result at all. This means that the column containing the value you look up should always be located to the left of the column containing the return value.

This example shows a small list where the value we want to search on, Chicago, isn't in the leftmost column. It's found in row 4. The formula used is shown in cell A If you want to experiment with lookup functions before you try them out with your own data, here's some sample data.

Copy the following data into a blank spreadsheet. Using an approximate match, searches for the value 1 in column A, finds the largest value less than or equal to 1 in column A which is 0. Using an approximate match, searches for the value 1 in column A, finds the largest value less than or equal to 1 in column A, which is 0.

Using an exact match, searches for the value 0. Because there is no exact match in column A, an error is returned.

Using an approximate match, searches for the value 0. Because 0. Using an approximate match, searches for the value 2 in column A, finds the largest value less than or equal to 2 in column A, which is 1. Copy all the cells in this table and paste it into cell A1 on a blank worksheet in Excel.

Looks up "Axles" in row 1, and returns the value from row 2 that's in the same column column A. Looks up "Bearings" in row 1, and returns the value from row 3 that's in the same column column B. Looks up "B" in row 1, and returns the value from row 3 that's in the same column. Because an exact match for "B" is not found, the largest value in row 1 that is less than "B" is used: "Axles," in column A.

Looks up "Bolts" in row 1, and returns the value from row 4 that's in the same column column C. Looks up the number 3 in the three-row array constant, and returns the value from row 2 in the same in this case, third column. There are three rows of values in the array constant, each row separated by a semicolon. Because "c" is found in row 2 and in the same column as 3, "c" is returned. Because the date is returned as a number, we use the TEXT function to format it as a date.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I have an excel workbook with multiple instances of the same client ID. So, a client can appear more than once in the list. I would like to find the last closest to the bottom instance of the client ID so i can then look along that same row for additional information.

So, how do I find the last instance of a given client ID using built in functions? I'd rather not write a macro to do this. Since array contains only 1 or DIV0! Learn more.

Asked 5 years, 11 months ago. Active 2 years, 5 months ago. Viewed 13k times. Active Oldest Votes. Robin Mackenzie Dmitry Pavliv Dmitry Pavliv I'm getting it to work, but I have no idea why. What is the 2 for in your formula? Thanks very much, but I still don't really understand.

Before you put together these functions you need to understand them individually. And, here you have a quick intro and syntax details about both. INDEX function returns a value from a column by specifying the position of the cell. You just need to specify a range and the cell number from which you need to get the value. The position of the value in the list is 6th row. So, now you need to refer to that column and specify the row which is 6.

## INDEX & MATCH Functions Combo in Excel (10 Easy Examples)

And, index function will return that value. MATCH function lookup for a value in a column or in a row and return the position of the cell where that value is.

You just need to specify the column or row from which you want to match the value and the value to match. In match function, just need to enter the name in the employee and refer to the column or the row. When we use MATCH, it looks up for the value from the lookup column and return the cell number of that value. Now, if look at data, in the column where you have cities, that is our lookup column and the column where you have employees name, that is your value column.

Get Access to Sample Files: Make sure to download these samples files from here to follow along each and every example. Here we have a data table with employee ID and name. First of allMATCH matches the emp id in the emp id column and returns the cell number of id for which you are looking for.

First of allyou have referred to the amount column in index function. This is the column from where we need to get the value. And in the end, INDEX use that number to return the amount by positioning the cell from the amount column. Approximate lookup can be useful when the value for which you are looking for is not there on the list and you want to get the closest match for that. In a two-way lookup, we need to get a value from a table.That's a shame. The INDEX function in Excel is fantastically flexible and powerful, and you'll find it in a huge number of Excel formulas, especially advanced formulas.

For example, let's say you have a table of planets in our solar system see belowand you want to get the name of the 4th planet, Mars, with a formula. What if you want to get the diameter of Mars? In that case, we can give INDEX both a row number and a column number, and feed in a larger array range of data. To summarize, INDEX gets a value at a specified location in a range of cells based on numeric position.

When the range is one-dimensional, you only need to supply a row number. When the range is two-dimensional, you'll need to supply both the row and column number. At this point, you may be thinking "So what? How often do you actually know the position of something in a spreadsheet? For example, we can use MATCH to get the position of the word "peach" in this list of fruits like this:.

MATCH doesn't care if the list is horizontal or vertical. Match type is important and controls whether matching is exact or approximate. The table below summarizes the options:. However, if you need an approximate match to lookup values along a scale, you'll want to use either 1 or -1, and you'll need to sort the lookup array according to your needs, [A-Z] when match type is 1, [Z-A] when match type is Approximate matching is useful when you want to find the best match in a scale of values, but it can be a disaster when you need an exact match.

I recommend always setting match type explicitly to avoid unwelcome surprises. Let's say we want to write a formula that returns the sales number for February for any given salesperson. Working one step at a time, let's leave the column hardcoded as 2 and make the row number dynamic. How will we do that? Naturally, we don't want to hardcode the name either. To keep things simple, we hardcoded the column number 2 to get sales for February. For example, this formula return the position of March, which is But of course we don't want to hardcode any values, so let's update the worksheet to allow the input of a month name, and use MATCH to find the column number we need.

The screen below shows the result:. Note: you could use Data Validation to create simple dropdown menus for both salesperson and month. It's simply a more flexible way to look things up. It's an excellent function with it's own benefits:.

Skip to main content. Excel formula video training - quick, clean, and to the point. Related courses. Core Formula. You must have JavaScript enabled to use this form.

The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

I have an index match formula which goes through a list and returns a date based on an email address. My issue I have is what if there are multiple entries that match that email address? How do I return the most recent date? Basically saying where you find the email address in A1 listed in column A of worksheet 1, return in B1 the value in the column of that row in worksheet1.

The thing is we could have the same email address listed a number of times, so I'm looking for the latest date to be returned, not the first one it finds. If however you have a lot of emails in sheet 2 that you want to look-up, another approach is needed. If that is the case, you can try this Array Formula.

As you can see, it has the same result as the DMAX. But you can copy and paste or auto-fill this formula to succeeding cells in B.

Learn more. Asked 5 years, 10 months ago. Active 5 years, 10 months ago. Viewed 28k times. Thanks simon. L42 Active Oldest Votes. L42 L42 Sorry, i didn't realise there would be an difference based on the numbers involved.

This is because Excel's behavior changes depending on two factors: whether you are performing an exact or approximate match, and whether data is sorted or not. Which price will we get? When doing an exact match, you'll always get the first match, period. It doesn't matter if data is sorted or not. In the screen below, the lookup value in E5 is "red".

If you are doing an approximate match, and data is sorted by lookup valueyou'll get the last match. Because during an approximate match Excel scans through values until a value larger than the lookup value is found, then it "steps back" to the previous value. With standard approximate match lookups, data must be sorted by lookup value. With unsorted data, you may see normal-looking results that are totally incorrect.

To illustrate this problem, see the example below. The argument is optional, but providing a value makes you think about it, and provides a visual reminder in the future. At this point, you may be feeling a little confused and disoriented about the idea that approximate match can return the last match in some cases. If so, don't worry.

### Get last match

Using approximate match to get the last match is not the "normal" case. Typically, you'll see approximate match used to assign values according to some kind of scale. In cases like this, the lookup table deliberately does not include duplicate values, so the whole idea of "last matching value" is irrelevant. More details on this formula here. The information above is to provide background and context for how matching works in Excel, so that the approaches described below make sense.

How can we use the behavior described above in a practical situation? Notice data is sorted by item, then by date, so the latest price for a given item appears last:. Other lookup functions can be used this way as well. Notice MATCH is configured to approximate match for items sorted in ascending order by setting the third argument to The formula is quite simple:.

What if you want the last match, but data isn't sorted by lookup value? This means we can dynamically build a lookup array to locate the data we want using simple logical expressions. You may not have seen a formula like this before, so let's break it down in steps.

Working from the inside out, we first apply the criteria with a simple logical expression:.

How to use VLookup to get multiple values

Next, we divide the number 1 by this array. This may seem puzzling. It won't. It will scan through the 1s looking for a 2 that will never be found. However, you can certainly use an array formula if you like. For example, by tweaking the logic a bit, we can do things like find the last non-empty cell in a column:. If you've made it this far, you may be wondering how you would find the second or third match, or how you would retrieve all matches?And many of these are simply awesome.

And today, I am writing this article solely focussed on Index Match to show you some simple and advanced scenarios where you can use this powerful formula combo and get the work done.

As soon as you tell the satellite the latitude and longitude coordinates, it will know exactly where to go and find that location. So despite having a mind-boggling number of lat-long combinations, the satellite would know exactly where to look.

The INDEX function will use the row number and column number to find a cell in the given range and return the value in it.

After all, in most cases, you are not likely to know the row and column numbers. The first one is used in most cases. The second one is used in advanced cases only such as doing a three-way lookup which we will cover in one of the examples later in this tutorial. Going back to my previous example of longitude and latitude, MATCH is the function that can find these positions in the Excel spreadsheet world.

As soon as it finds the name, it returns the position in that specific range. Click here to download the example file. Suppose you have the same data, but instead of having it in columns, you have it in rows as shown below. A lot of times, you may be required to fetch the data from a column which is to the left of the column that has the lookup value.

So far, we have seen the examples where we wanted to fetch the data from the column adjacent to the column that has the lookup value. The below formula will give you the marks for Jim for all the three subjects copy and paste in one cell and drag to fill other cells or copy and paste on other cells. This becomes the row number from which the data needs to be fetched.

For example, Math is 1, Physics is 2 and Chemistry is 3. This formula is dynamic, which means that if you change the student name or the subject names, it would still work and fetch the correct data. One way of doing this is to create a helper column and combine the names.

You can create a formula that handles multiple criteria in the formula itself. You provide the row and column number, and it returns the value in that specific cell. Similarly, if you use 0 as the row number, it will return all the values in the column. You can check this by selecting the formula and press the F9 key. Just like we have done this for a student, you can also do this for a subject. For example, if you want the average score in a subject, you can keep the row number as 0 in the INDEX formula and it will give you all the column values of that subject.

But sometimes, you need to know the range in which your lookup values lie. This is usually the case with numbers. Below is an example, where I want the grade for all the students and the grading is decided based on the table on the right. This argument will return the largest value that is less than or equal to the lookup value. This means that the MATCH formula goes through the marks range, and as soon as it finds a marks range that is equal to or less than the lookup marks value, it will stop there and return its position.

For example, if I change the order of the grade table as shown belowI can still find the grades of the students. For example, suppose I have the following data set of students where there are two students with the name Jim the only difference being that one is entered as Jim and another one as jim. Below is the formula that will give you the right result.

Suppose you have a dataset where you want to find the person who has the work experience closest to the required experience mentioned in cell D2. While lookup formulas are not made to do this, you can combine it with other functions such as MIN and ABS to get this done. Below is the formula that will find the person with the experience closest to the required one and return the name of the person.

Note that the experience needs to be closest which can be either less or more. The trick in this formula is to change the lookup value and lookup array to find the minimum experience difference in required and actual values.

You will go through each cell in column B and find the difference in the experience between what is required and the one that a person has. Once you have all the differences, you will find the one which is minimum and fetch the name of that person.