Power Query: Create a Multi-Level Data Lineage Table
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.
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.
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.
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.
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.
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.
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.
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.
Use a recursive SQL query for large relationship datasets
Choose this option when the relationship table is large or the database can process recursive paths more efficiently than Power Query.
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. Open the relationship workbook: Launch WPS Office and choose Spreadsheet > Open to load the existing XLSX relationship table.
- 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. Save in a compatible format: Choose Menu > Save As and select Excel Workbook (*.xlsx) when the file must be shared with Microsoft Excel users.

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.




