Power Query Problems

Power Query: Create a Multi-Level Data Lineage Table

Phi Hung VoPhi Hung Vo Nov 12, 2026 870 views

Question details

The user needs to transform source-to-target database, table, and column relationships into one multi-level data lineage table.

Product
Microsoft Excel Power Query
Device & OS
not provided
Scenario
A relationship table contains source and target fields, and each target may become the source for the next relationship. The goal is to follow every hop from the original source and combine the results into one row per starting source.
Observed behavior
Power Query can identify successive relationships, but the expected lineage output may include blank separator rows or may require additional clarification about how each hop should be grouped.
Before you start

Confirm that the source and target database, table, and column fields use consistent names and data types. Identify whether blank separator rows should remain in the final output before building the query.

Solution 1Recommended

Build an iterative self-join in Power Query

Use this approach when each target relationship can become the source of the next hop and the lineage must be generated from the relationship table.

Match the current database, table, and column values to the next row's source database, table, and column values. Start with the original source, append each matched target as the next hop, and continue until no matching target remains.

1
Load and standardize the relationship table

In Excel, select the relationship range and choose Data > From Table/Range. In Power Query Editor, set matching database, table, and column fields to consistent text types and remove completely blank records.

2
Create the next-hop matching key

Choose Add Column > Custom Column and combine the current database, table, and column values into a key. Create the same combined key from the source database, table, and column fields used for the next relationship.

3
Join each target to the next source

Select Home > Merge Queries, join the current target key to the next source key, and use a Left Outer join. Expand the matched target database, table, and column fields to add the next lineage hop.

4
Repeat until no match remains

Continue the self-join or iterative function until the expanded target fields are null, indicating that the relationship chain has ended. Keep the original source fields so every hop remains tied to its starting point.

5
Combine and clean the lineage output

Use Transform > Group By or a custom Power Query function to combine the hops into one row per original source. Select the blank separator rows, choose Home > Remove Rows > Remove Blank Rows, and then select Home > Close & Load.

Check for circular relationships: Add a visited-key check or maximum hop count when the data may contain cycles. This prevents the iterative query from continuing indefinitely.
Free Microsoft Office alternative

Explore WPS Office for Compatible Spreadsheet Lineage Workflows

WPS Office is a free, lightweight Microsoft Office alternative for reviewing relationship data, organizing lineage tables, and continuing spreadsheet-based analysis with a familiar interface. It supports common Microsoft Office formats for seamless migration, although Microsoft Power Query-specific transformations should remain in Excel or the connected database.

  1. 1. Open the relationship workbook: Launch WPS Office and choose Spreadsheet > Open to load the existing XLSX relationship table.
  2. 2. Review and organize lineage fields: Use the Data tab to sort and filter source and target database, table, and column fields, then format the results as a readable table.
  3. 3. Save in a compatible format: Choose Menu > Save As and select Excel Workbook (*.xlsx) when the file must be shared with Microsoft Excel users.
Free and lightweight spreadsheet tools for organizing source-to-target relationship dataFamiliar interface that helps Microsoft Office users migrate with minimal effortCompatible with Microsoft Excel XLSX files for easier sharing and continued editingUseful sorting, filtering, and table formatting features for reviewing lineage results
microsoft office alternative - wps office

Frequently Asked Questions

How do I match a target row to the next source row in Power Query?

Create a key from the target database, table, and column fields, then merge it with a key made from the next row's source database, table, and column fields. Use Home > Merge Queries and expand the matching target columns.

How can I stop a Power Query lineage process from looping forever?

Add a visited-key check or a maximum hop count to the iterative logic. A cycle exists when a later target key matches a key already encountered in the same lineage path.

How do I create one lineage row for each original source?

Preserve the original source fields throughout the iterations, then use Transform > Group By on those fields and combine the hop columns or records into a single lineage value.

Can blank separator rows be removed from the Power Query result?

Yes. In Power Query Editor, select Home > Remove Rows > Remove Blank Rows. You can also filter out rows where the key or required source fields are null or empty.

Is SQL better than Power Query for very large lineage datasets?

It can be. A recursive SQL query runs close to the source database and may handle large relationship graphs more efficiently, while Power Query is convenient for workbook-based transformations and moderate-sized datasets.