Power Query Problems

Extract a City Name from a URL in Excel Power Query

Rana GarciaRana Garcia Dec 2, 2026 868 views

Question details

Extract a city name from the final section of a URL and add it to a Power Query result.

Extract a City Name from a URL in Excel Power Query
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the query

In Excel, select a cell in the source table and choose Data > From Table/Range, or open an existing query from Data > Queries & Connections.

2
Create a custom column

In Power Query Editor, select Add Column > Custom Column. Enter City as the new column name.

3
Enter the extraction formula

In the custom column formula box, enter Text.AfterDelimiter([URL], "/", {0, RelativePosition.FromEnd}). Replace URL with the actual column name, then select OK.

4
Load the result

Check the new City column in the preview, then select Home > Close & Load to return the result to Excel.

Add a custom column for the final URL segment
Check URL formatting: A trailing slash produces an empty result, and a query string remains attached to the extracted text. Remove these parts before extraction if needed. The formula returns the final segment, which is not necessarily a city.
Free Microsoft Office alternative

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.

Review and edit URL data in spreadsheetsCompatible with Microsoft Excel XLSX and XLS filesFamiliar spreadsheet interface for a smoother transitionFree and lightweight office suite
microsoft office alternative - wps office

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.