Last active
June 9, 2024 22:32
-
-
Save ExcelRobot/7de6f93f52604e01d58f859755a4bac9 to your computer and use it in GitHub Desktop.
Street Sort Lambda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Name: Sort Street Addresses (StreetSort) | |
Description: Sorts a list of street addresses so that the street names are together with the address number in the correct order. Also supports proper sorting of street names like 1st Street, 2nd Street, 10th Street into numerical order. | |
Parameters: | |
addresses - array of street addresses (ie: 123 Main Street) | |
Source: Excel Robot (@ExcelRobot) | |
*/ | |
StreetSort =LAMBDA(addresses, LET( | |
\\LambdaName, "StreetSort", | |
\\CommandName, "Sort Street Addresses", | |
\\Description, "Sorts a list of street addresses so that the street names are together with the address number in the correct order. Also supports proper sorting of street names like 1st Street, 2nd Street, 10th Street into numerical order.", | |
\\Parameters, {"addresses", "array of street addresses (ie: 123 Main Street)"}, | |
\\Source, "Excel Robot (@ExcelRobot)", | |
_NumberPart, TEXTBEFORE(addresses, " ", 1), | |
_StreetPart, TEXTAFTER(addresses, " ", 1), | |
_FirstWord, TEXTBEFORE(_StreetPart, " ", 1, , , _StreetPart), | |
_IsNumeric, ((RIGHT(_FirstWord, 2) = "st") + (RIGHT(_FirstWord, 2) = "nd") | |
+ (RIGHT(_FirstWord, 2) = "rd") | |
+ (RIGHT(_FirstWord, 2) = "th")) | |
* NOT(ISERROR(VALUE(LEFT(_FirstWord, LEN(_FirstWord) - 2)))) | |
= 1, | |
_AddressNumber, IFERROR(VALUE(_NumberPart), _NumberPart), | |
_StreetNumber, IF( | |
_IsNumeric, | |
VALUE(LEFT(_FirstWord, LEN(_FirstWord) - 2)), | |
NA() | |
), | |
_Result, SORTBY( | |
addresses, | |
IF(_IsNumeric, _StreetNumber, _StreetPart), | |
1, | |
_AddressNumber, | |
1 | |
), | |
_Result | |
)); |
Author
ExcelRobot
commented
Jun 9, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment