How to make index function only pull figures if cell adjacent hits required criteria

New Contributor

I'm currently using this formula:


From this website:



This worked well for an overall modal value. But my figures (range A1:A100) have an adjacent cell with the years next to it. I want to create a table to provide an automated modal value for each year. 






In this example, the formula would return a mode of X, however, this X is only the mode for the entire table, and for years 2018 and 2019. In 2020 there were no cases of X, only Y. 


I want the formula to be able to check the year in the adjacent cell from the entire table, and only output the modal value for that specific year in this approximate format:



Is there any way to incorporate this into the formula or will i need to manually create new tables per year? VLOOKUP perhaps?

4 Replies
best response confirmed by SSBColliers (New Contributor)


My suggested solution would be, you can use the INDEX and MATCH functions with multiple criteria to look up values based on the year.

 You can use this generic formula syntax:


In your case, you can use something like this:


Where year is the cell that contains the year you want to check.

This is an array formula and must be entered with Control + Shift + Enter in Legacy Excel or just Enter in Excel 365.

Thank you for your response.

Unfortunately, this didn't seem to work. I forgot to disclose that the table with the raw data is on a separate sheet. Does this have an effect on the formula? I get an "#N/A" error.

Perhaps I've entered the ranges wrong.

The range for the name is:

The range for the year is:

The table with the raw data is formatted as a table. Does this also have an effect?
Hi Nikolino. This worked.

I have another question. Very similar. Would you suggest i post it here? Or should i create a new discussion. I think you'll be able to answer it very easily as it is basically the same q.



The formula you entered is not working because you need to specify the sheet name where the raw data is located. For example, if the sheet name is “Data”, you can use this formula:



Also, make sure that the year value is a number and not text.

You can use the VALUE function to convert text to number if needed.


The table format does not affect the formula, but you can use structured references instead of cell ranges if you want. For example, if the table name is “Table1”, you can use this formula: