Explanation
At the core, this formula is a basicINDEX and MATCH formula.
A match mode value of 1 tells XMATCH to find an exact match ornext largest value.
Regardless of order, MATCH will return the first exact match or next largest value.
Note: in the even of a tie, XMATCH will return the first match for tied values.
Get distance
The formula to return the actual distance of the nearest location is almost the same.
Instead of giving INDEX the location names, we give INDEX the distances.
you’ve got the option to use INDEX to retrieve individual values, or entire rows and columns.
It is a more robust and flexible successor to the MATCH function.
XMATCH supports approximate and exact matching, reverse search, and wildcards (* ?)