Last matching Value in multiple Columns

Emre06

New Member
Joined
Sep 27, 2023
Messages
19
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello, i have 2 Columns containing guards's names. ( I tried to use "maxifs" function but it is working only for one column ) My Question is: I need formula to find "Last Date" of "John Fizz" in "Beach"?

Kitap1 (version 1).xlsb
ABCD
1DateGuard 1Guard 2Location
21.02.2023Mike RogersRomeo LoiLobby
32.02.2023John FizzTaric BenBeach
43.02.2023Alan DuskLora IanHotel
54.02.2023Clark KentJohn FizzBeach
Sayfa1
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Excel Formula:
(XMATCH("John FizzBeach",B:B&D:D,0,-1)

This bit is looking for the row index from the bottom up for the string "John FizzBeach" when columns B and D join together. (Guard 1)

Excel Formula:
(XMATCH("John FizzBeach",C:C&D:D,0,-1)
Same thing for this bit but looking in columns C and D (Guard 2)

At this point, you have a row index for Guard 1 and Guard 2, but you want the latest so we apply the MAX().

Then use INDEX() to return the date from Column A, with the row index.
 
Upvote 1
@Emre06 - you also need to aware that the XMatch option supplied gets the "last matching" value in the table (that is what the "-1" at the end of the function does - tells it to look from the bottom up). This means your date column needs to be sorted in ascending order.

Here is another option:
Note:
* is AND logic ie both need to be true
+ is OR logic ie one or more need to be true

Excel Formula:
=MAX(
            FILTER( $A$2:$A$10,
                          (($B$2:$B$10=G2)*($D$2:$D$10=H2))
                          +(($C$2:$C$10=G2)*($D$2:$D$10=H2))
                          )
           )
 
Upvote 1
Thank you it worked. I tried to use same formula for others but there is a problem. If I use same formula for "Mike Rogers" ( Hes only been as First Guard not second) formula gives error ?

This will work when that happens but @Alex Blakenburg has a shorter solution.

Excel Formula:
=LET(guard1,XMATCH(C2&D2,B:B&D:D,0,-1),guard2,XMATCH(C2&D2,C:C&D:D,0,-1),IFERROR(INDEX(A:A,MAX(IF(ISNUMBER(guard1),guard1,-1),IF(ISNUMBER(guard2),guard2,-1))),"Not found"))
 
Upvote 1
@BigBeachBananas Thank you very much !


Thank you very much for you kind help Sir. Sorry But Firstly cannot copy code, I think spaces are giving me problem. And G2 value and H2 value is empty I suppose ? I couldnt manage to use that :(

Excel Formula:
=MAX(FILTER(A:A,(B:B="John Fizz")*(D:D="Beach")+(C:C="John Fizz")*(D:D="Beach")))

Replace "John Fizz" and "Beach" with your cell references.
 
Upvote 1
@BigBeachBananas Thank you very much !


Thank you very much for you kind help Sir. Sorry But Firstly cannot copy code, I think spaces are giving me problem. And G2 value and H2 value is empty I suppose ? I couldnt manage to use that :(
1) Did you
a) click on the copy symbol in the top right corner of the grey area that contains the formula ?
b) copy the code directly into the formula bar ? (not into the cell)
2) G2 is where I had the name to be used by the formula and H2 where I had the location, you need to put in your own cell references for that.
Your example shows B3 & D3 but seems a bit unlikely since it is in the range to be searched.

BigBeachBananas has now supplied the flattened out version, I was just trying to make the formula logic more obvious by using spaces and Alt+Enter to structure the formula
 
Upvote 1
By the way is there a way to conditional format #N/A error ?
I was going to throw that in but opted to keep it to the essentials in the first pass.
Just wrap the whole thing in an IFERROR,
So before the Max add
IFERROR(
then at the end add
,"")
Or you could but something like Not Found between the quotes.
 
Upvote 1
Try this. I have also rearranged it a little so you don't need to evaluate the location twice.

Excel Formula:
=MAX(FILTER(A:A,((B:B="John Fizz")+(C:C="John Fizz"))*ISNUMBER(SEARCH("Beach",D:D))))
 
Upvote 1
Solution

Forum statistics

Threads
1,215,681
Messages
6,126,194
Members
449,298
Latest member
Jest

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top