Extract a City Name from a URL in Excel Power Query
Question details
Extract a city name from the final section of a URL and add it to a Power Query result.

- Product
- Microsoft Excel Power Query
- Device & OS
- not provided
- Scenario
- A query contains URLs whose final path segments represent city names.
- Observed behavior
- The desired output is a new column containing the final URL path segment for each row.
Check that the URLs have a consistent structure and that the city is the final path segment. Note any trailing slashes, query strings, or blank values, which may affect the result.
Add a custom column for the final URL segment
Use this method when each URL ends with a city name and has no trailing slash or query string.
In Excel, select a cell in the source table and choose Data > From Table/Range, or open an existing query from Data > Queries & Connections.
In Power Query Editor, select Add Column > Custom Column. Enter City as the new column name.
In the custom column formula box, enter Text.AfterDelimiter([URL], "/", {0, RelativePosition.FromEnd}). Replace URL with the actual column name, then select OK.
Check the new City column in the preview, then select Home > Close & Load to return the result to Excel.

Work with URL data in WPS Spreadsheets
WPS Office is a free, lightweight, easy-to-use Microsoft Office alternative with a familiar interface. Open compatible Excel workbooks in WPS Spreadsheets for a smooth transition when reviewing and editing URL data; it does not fix Microsoft Power Query itself.

Frequently Asked Questions
What if my URL column has a different name?
In Add Column > Custom Column, replace [URL] in the formula with your actual column reference, such as [Web Address].
Why is the extracted city blank?
If the URL ends in a slash, the text after the last slash is empty. Remove trailing slashes in Power Query before applying the extraction formula.
Will the formula remove a URL query string?
No. For a URL ending in /boston?ref=1, the result includes boston?ref=1. Remove the query string before extracting the final path segment.
Can I use the formula with a text value already defined in a query?
Yes. In the Power Query Advanced Editor, use Text.AfterDelimiter(getAddress04, "/", {0, RelativePosition.FromEnd}) if getAddress04 contains the URL text.




