Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I am working in Excel Power Query and I am trying to take a table that details relationships between two values example below
From | To |
A | B |
B | C |
C | D |
C | E |
X | Y |
Y | Z |
And output this
From | To |
A | {B,C,D,E} |
X | {Y,Z} |
Would really appreciate a steer or pointers about how I can do this.
Solved! Go to Solution.
let
dataTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXJSitWJBpI6Ss5gljOQ5QJnuYJZEUBWJJgVCWRFKcXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [From = _t, To = _t]),
fx = (tbl, s) =>
let
a = List.Combine(List.Transform(s, (v) => Table.SelectRows(tbl, each [From] = v)[To]))
in
if List.Count(a) = 0 then {} else (a & @Fx(tbl, a)),
result = Table.AddColumn(
Table.SelectRows(dataTable, each Table.RowCount(Table.SelectRows(dataTable, (r) => r[To] = [From])) = 0)[[From]],
"To",
each "{" & Text.Combine(fx(dataTable, {[From]}), ",") & "}"
)
in
result
Amazing!, thank you!
let
dataTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXJSitWJBpI6Ss5gljOQ5QJnuYJZEUBWJJgVCWRFKcXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [From = _t, To = _t]),
fx = (tbl, s) =>
let
a = List.Combine(List.Transform(s, (v) => Table.SelectRows(tbl, each [From] = v)[To]))
in
if List.Count(a) = 0 then {} else (a & @Fx(tbl, a)),
result = Table.AddColumn(
Table.SelectRows(dataTable, each Table.RowCount(Table.SelectRows(dataTable, (r) => r[To] = [From])) = 0)[[From]],
"To",
each "{" & Text.Combine(fx(dataTable, {[From]}), ",") & "}"
)
in
result
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.