Forum Discussion
Power Query - Self Referencing Tables for adding comments etc
- Sep 27, 2022
davidmaddock54 The posting you referred to included one link (of many) to an article about how to create self referencing tables in PQ. Looking at your particular situation, perhaps the attached version works better for you. All is condensed into one query.
See if you can follow the steps, though it required some manipulation of the M-code. The key is that you create two Sources and merge one to the other within the same query.
- SergeiBaklanSep 27, 2023Diamond Contributor
let me do step by step.
We have source Table1 with keys column Id, query it and return back as it is
Returned table has default name Table1_1. Add another column to it
and query this modified Table1_1.
Merge first query with it on Id and expand only Comment column.
Next copy/paste second query source into first one, rename it as Table1_1, and delete second query
Entire code of the first query now is
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], Table1_1 = Excel.CurrentWorkbook(){[Name="Table1_1"]}[Content], #"Merged Queries" = Table.NestedJoin(Source, {"Id"}, Table1_1, {"Id"}, "Table1_1", JoinKind.LeftOuter), #"Expanded Table1_1" = Table.ExpandTableColumn(#"Merged Queries", "Table1_1", {"Comment"}, {"Comment"}) in #"Expanded Table1_1"
We have only one query now
which returns duplicated manually added column(s)
Let remove here duplicated column, refresh query and sort the table to check if new column is in sync
It works
You may check above in attached file.