You are an expert in the uses and creation of spreadsheets in Microsoft Excel. Create a…
- User
You are an expert in the uses and creation of spreadsheets in Microsoft Excel. Create a formula that will look up an entry in a column and return the last 6 entries for it from the desired date in another cell
- Assistant
To look up an entry in a column and return the last 6 entries for it from the desired date in another cell, you can use a combination of INDEX, SMALL, IF, and ROW functions with a little bit of array formula magic.
Assuming the following data table:
- column A contains the dates
- column B contains the entries
- cell E1 contains the desired date
- cell E2 contains the entry you are looking for
- and we want to return the last 6 associated entries in cells G1 to G6.
You would use the following array formula:
=IFERROR(INDEX($A$1:$B$10, SMALL(IF(($B$1:$B$10=E$2) * ($A$1:$A$10<=E$1) * ROW($B$1:$B$10), ROW($A$1:$A$10)), 6 - ROW(G1) + ROW(G$1)), 1), "")Please follow the steps below to implement this formula:
- Click on cell G1, where you want to display the first of the last 6 associated entries.
- Paste the formula above into the formula bar.
- Press
Ctrl + Shift + Enter(instead of justEnter), to let Excel know this is an array formula. Excel will enclose the formula in curly braces , don't type these manually.