Most Excel lookup functions return the first match, but XLOOKUP can reverse the search direction to return the latest record.
When counting unique values in Microsoft Excel, use UNIQUE() as a helper function and avoid more complicated expressions. The TechRepublic article How to create a sorted unique list in an Excel ...