Excel: Return row number if value of a cell in a column matches a cell in another column and another condition is matched in yet another column

I needed to do this at work (SPG), and google's AI worked marvelously, as easy as it maybe for advanced Excel Formula experts which I am not.

Ingenious solution by Google:

In Excel, you can return a row number based on multiple criteria using a combination of the INDEX and MATCH functions. For users with newer versions of Excel (Microsoft 365, 2021), the FILTER function is a more straightforward alternative. 

Example scenario

Imagine you have a table with sales data that includes ProductRegion, and Sales. Your goal is to find the row number for the entry where the Product is "Mug" and the Region is "West".

ABC
1ProductRegionSales
2T-ShirtEast$150
3MugWest$200
4T-ShirtWest$120
5MugEast$180

Formula:
=MATCH(1, (A2:A5="Mug")*(B2:B5="West"), 0)

How it works:

  • (A2:A5="Mug") creates an array of TRUE or FALSE values. In our example, it becomes {FALSE;TRUE;FALSE;FALSE}.
  • (B2:B5="West") does the same for the second condition, creating {FALSE;TRUE;TRUE;FALSE}.
  • The multiplication operator * acts as an AND operator. Excel treats TRUE as 1 and FALSE as 0, so the formula multiplies the two arrays element by element. Only the row where both conditions are TRUE will result in a 1. The resulting array is {0;1;0;0}.
  • MATCH(1, {0;1;0;0}, 0) then searches for the value 1 in this new array and returns its relative position. In this case, it's the second position. 
This entry was posted in Computer Science. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.