Power Query Problems

Create City and Keyword Combinations in Excel with Power Query

Aamir Naveed AkramAamir Naveed Akram Dec 2, 2026 868 views

Question details

Create every city and keyword text combination, separated by a space, from lists that may include keywords in multiple columns.

Create City and Keyword Combinations in Excel with Power Query
Product
Microsoft Excel Power Query
Device & OS
not provided
Scenario
The user has up to 1,000 cities and 300 keywords and wants a complete list of city-keyword pairs.
Observed behavior
The desired result is one row for each city and keyword pair, with a space between the two values.
Before you start

Place the cities in one column and the keywords in one or more columns, with headers and no unrelated data in either range. Confirm that Power Query is available on Excel's Data tab and check that the expected output will fit on a worksheet.

Solution 1Recommended

Cross join the lists with Excel Power Query

Use a constant key to pair every city with every keyword, even when the keywords start in multiple columns.

A cross join produces one row for every possible pair. For example, 1,000 cities and 300 keywords produce 300,000 rows; duplicate source values produce duplicate combinations.

1
Load the city list

Select the city range, choose Insert > Table, and confirm that the table has headers. With a cell in the table selected, choose Data > From Table/Range. In Power Query, name the city column City and filter out blank cities.

2
Load and unpivot the keywords

Create a separate Excel table from the keyword range and open it with Data > From Table/Range. In Power Query, select all keyword columns and choose Transform > Unpivot Columns. Remove the Attribute column, rename Value to Keyword, and filter out blank keywords.

3
Add a matching key

In each query, choose Add Column > Custom Column. Name the column JoinKey and enter 1 as the formula. Set JoinKey to the Whole Number data type in both queries.

4
Merge the queries

Select the city query and choose Home > Merge Queries > Merge Queries as New. Select the keyword query as the second table, select JoinKey in both tables, and choose Inner as the join kind. Select OK.

5
Expand and combine the values

Select the expand button on the merged column, keep only Keyword, and select OK. Choose Add Column > Custom Column and enter Text.From([City]) & " " & Text.From([Keyword]) to create the combined text.

6
Load the results

Remove JoinKey and any other columns you do not need, then choose Home > Close & Load to place the results in Excel. To regenerate the list after source changes, use Data > Refresh All.

Cross join the lists with Excel Power Query
Check the output size: The number of rows equals the number of nonblank cities multiplied by the number of nonblank keywords. An Excel worksheet has a limit of 1,048,576 rows, including the header.
Create combinations with WPS Spreadsheets

Generate city and keyword pairs with WPS Spreadsheets formulas

Use INDEX, ROWS, INT, and MOD in WPS Spreadsheets to generate each city-keyword pair without Power Query. First consolidate the keywords into a single column.

  1. 1. Prepare the city list: Open the workbook in WPS Spreadsheets. Create a sheet named Cities and place the city header in A1 and the nonblank city values below it.
  2. 2. Consolidate the keywords: Create a sheet named Keywords and place a header in A1. Copy the values from each keyword column and paste them one below another in column A, without blank rows between them.
  3. 3. Enter the combination formula: On a new sheet, enter a header in A1. In A2, enter =INDEX(Cities!$A$2:$A$1001,INT((ROW()-2)/ROWS(Keywords!$A$2:$A$301))+1)&" "&INDEX(Keywords!$A$2:$A$301,MOD(ROW()-2,ROWS(Keywords!$A$2:$A$301))+1). Change 1001 and 301 to the actual last rows of the city and keyword lists.
  4. 4. Fill the result rows: Multiply the city count by the keyword count. Select A2 through the row equal to that total plus one, then use Ctrl+D or the Fill Down command to copy the formula. For 1,000 cities and 300 keywords, fill through A300001.
  5. 5. Save the workbook: Choose File > Save As and select an Excel-compatible XLSX format. If you add or remove source rows, update the formula ranges and fill the required number of result rows again.
Generate a complete list of city and keyword combinations with a space between each pair.Open and save Microsoft Excel XLSX workbooks.Use familiar spreadsheet formulas and worksheet controls.Refresh the results by recalculating after editing values within the referenced ranges.
microsoft office alternative - wps office

Frequently Asked Questions

How many combinations will the cross join create?

Multiply the number of nonblank cities by the number of nonblank keywords. For example, 1,000 cities and 300 keywords create 300,000 rows.

Why do I need to unpivot the keyword columns?

Unpivoting turns keywords from multiple columns into one Keyword column, so the merge can pair every keyword with every city. Select the keyword columns in Power Query and choose Transform > Unpivot Columns.

How do I add a space between the city and keyword?

In Power Query, choose Add Column > Custom Column and use Text.From([City]) & " " & Text.From([Keyword]). The quoted space separates the two values.

Will duplicate cities or keywords create duplicate results?

Yes. Each source row participates in the cross join. If duplicates are not wanted, select the relevant column in Power Query and use Home > Remove Rows > Remove Duplicates before merging.

How can I update the combinations after changing the source lists?

Edit the source Excel tables, then choose Data > Refresh All. Power Query will rerun the unpivot and merge using the updated table data.