In this article, we will learn How to get the last entry by month in Excel.
Scenario:
When working with datasets, sometimes we need to extract some results based on different criteria. Here the problem criteria is the value must be the last entry corresponding to a given month. The problem can be interpreted in two ways.
You must be thinking what is the difference between the two. The difference is the first problem extracts the last entry from the column which matches the month name whereas the second problem extracts the nearest date value from the end of month date value. We will understand both situations one by one. Firstly we will be considering How to get the last entry in column by month.
How to get the Last entry in column by month in Excel?
For this we will be using the TEXT function and LOOKUP function. Here we use an attribute of LOOKUP function search for the last value. LOOKUP function takes 3 arguments lookup value, lookup array and result array. So we use the lookup array argument as 1/lookup array. For more details see the below formula syntax:
formula syntax :
=LOOKUP(2,1/(TEXT(dates,"mmyyyy")=TEXT(month,"mmyyyy")),values) |
dates : dates array in data
values : result array in data
month : month criteria
Example :
All of these might be confusing to understand. Let's understand how to use this formula in an example. Here we have data with date and Price values. For this we need the latest entry of January 2019 month which will be the last entry with date of Jan 2019. Here for the date array and Price array we used named ranges.
Use the formula:
=LOOKUP(2,1/(TEXT(dates,"mmyyyy")=TEXT(F9,"mmyyyy")),Price) |
Explanation:
{ "012019" ; "012019" ; "012019" ; "012019" ; "022019" ; "022019" ; "022019" ; "022019" ; "032019" ; "032019" ; "032019" ; "032019" ; "032019" }
{ 1 ; 1 ; 1 ; 1 ; #DIV/0! ; #DIV/0! ; #DIV/0! ; #DIV/0! ; #DIV/0! ; #DIV/0! ; #DIV/0! ; #DIV/0! ; #DIV/0! }
Named ranges used
dates : C3:C15
Price : D3:D15
The last Price is 78.48 corresponding to the 31-01-2019. Copy the formula to other cells using the Ctrl + D or dragging down from the bottom right corner of the cell.
As you can see the formula returns all the values required. The function returns #N/A error, if the lookup month value doesn't match any date entry. In the above example the date entries are in sorted manner. So the last entry of the month matches the last date entry of the month. Now if the date entries are not sorted, then we will first sort the date values and use the above formula.
How to get the Last date entry by month in column in Excel?
For this we will be using the VLOOKUP and EOMONTH function. The EOMONTH function takes the date value of month and returns the last date of the required month. VLOOKUP function finds the last date of month or the nearest previous date and returns a value corresponding to that value.
Use the formula :
= VLOOKUP ( EOMONTH (F3,0), table, 2) |
Explanation :
Here the formula returns the 78.48 as result. Now copy the formula to other cells using the shortcut Ctrl + D or dragging down from the right bottom corner of the cell.
As you can see the formula works fine. There is just one problem. As we look up the last date corresponding to the april month, the function returns the value corresponding from the March, as there is no entry of april date in table. Make sure to catch these results.
Here are all the observational notes regarding using the formula.
Notes :
Hope this article about How to get the last entry by month in Excel is explanatory. Find more articles on extracting values from the table using formulas here. If you liked our blogs, share it with your friends on Facebook. And also you can follow us on Twitter and Facebook. We would love to hear from you, do let us know how we can improve, complement or innovate our work and make it better for you. Write us at info@exceltip.com
Related Articles:
Find the last row with mixed data in Excel : working with numbers, text or blank cell in the same array. Extract the last row with non blank cell using the MATCH function in Excel.
Finding the Last Day of a Given Month : EOMONTH function returns the last date of the month, of the given date value.
How to Get Last Value In Column : Last entry in a large data, A combination of CELL and INDEX function returns the last value in a column or list of data.
Difference with the last non blank cell : takes the alternate difference from the last value in the list with numbers using the IF and LOOKUP function in Excel.
Find the last row of data with text values in Excel : In an array of text values and blank cells, return the last value in the array using the MATCH and REPT function in excel.
How to use the SUMPRODUCT function in Excel: Returns the SUM after taking the product of the corresponding values in multiple arrays in excel.
How to use wildcards in excel : Lookup, Count, sum, average and more mathematical operation on cells matching phrases using the wildcards in excel.
Popular Articles:
How to use the IF Function in Excel : The IF statement in Excel checks the condition and returns a specific value if the condition is TRUE or returns another specific value if FALSE.
How to use the VLOOKUP Function in Excel : This is one of the most used and popular functions of excel that is used to lookup value from different ranges and sheets.
How to use the COUNTIF Function in Excel : Count values with conditions using this amazing function. You don't need to filter your data to count specific values. Countif function is essential to prepare your dashboard.
How to use the SUMIF Function in Excel : This is another dashboard essential function. This helps you sum up values on specific conditions.
The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.