Explanation
The example shown contains almost 10,000 rows of data. The data represents temperature readings taken every 2 minutes over a period of days. For any given date (provided in cell H7), we want to get the maximum temperature on that date.
Inside the IF function , logical test is entered as B5:B9391=H7. Because we’re comparing the value in H7 against a range of cells (an array), the result will be an array of results, where each item in the array is either TRUE or FALSE. The TRUE values represent dates that match H7.
For the value if true, we provide the range E5:E9391, which fetches all the full set of temperatures in Fahrenheit. This returns an array of values the same size as the first array.
The IF function acts as a filter. Because we provide IF with an array for the logical test, IF returns an array of results . Where the date matches H7, the array contains a temperature value. In all other cases, the array contains FALSE. In other words, only temperatures associated with the date in H7 survive the trip through the IF function.
The array result from the IF function is delivered directly to the MAX function , which returns the maximum value in the array.
With MAXIFS
In Excel O365 and Excel 2019, the new MAXIFS function can find the maximum value with one or more criteria without the need for an array formula. With MAXIFS, the equivalent formula for the this example is:
=MAXIFS(E5:E9391,B5:B9391,H7)
Explanation
This is a standard “exact match” VLOOKUP formula with one exception: the column index is calculated using the COLUMN function. When the COLUMN function is used without any arguments, it returns a number that corresponds to the current column.
In this case, the first instance of the formula in column E returns 5, since column E is the 5th column in the worksheet. We don’t actually want to retrieve data from the 5th column of the customer table (there are only 3 columns total) so we need to subtract 3 from 5 to get the number 2, which is used to retrieve Name from customer data:
COLUMN()-3 = 2 // column E
When the formula is copied across to column F, the same formula yields the number 3:
COLUMN()-3 = 3 // column F
As a result, the first instance gets Name from the customer table (column 2), and the 2nd instance gets State from the customer table (column 3).
You can use this same approach to write one VLOOKUP formula that you can copy across many columns to retrieve values from consecutive columns in another table.
With two-way match
Another way to calculate a column index for VLOOKUP is to do a two-way VLOOKUP using the MATCH function . With this approach, the MATCH function is used to figure out the column index needed for a given column in the second table.