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'm working on a Power Query transformation in Power BI, and I'm facing a challenge that I need assistance with. I have a table with four columns: L0, L1, L2, and L3, representing hierarchical levels in a team structure.
Here is a sample of the original data:
L0 L1 L2 L3 chris damien lucia sai chris damien lucia rashim chris damien rachel
chris edwin
chris lisa mayur
chris lisa mayur geetha
->>>
let
Source = Table.FromRows({
{"chris", "damien", "lucia", "sai"},
{"chris", "damien", "lucia", "rashim"},
{"chris", "damien", "rachel", null},
{"chris", "edwin", null, null},
{"chris", "lisa", "mayur", null},
{"chris", "lisa", "mayur", "geetha"}
}, type table [L0 = text, L1 = text, L2 = text, L3 = text])
in
Source <----
I want to create new rows for the missing team members, so the table reflects the complete hierarchy. For example, in the above sample data, Lucia and Damien have missing rows in L3, and Lisa is missing in L2, and Chris missing in L0
The desired output should look like this:
L0 L1 L2 L3
chris damien lucia sai
chris damien lucia rashim
chris damien lucia
chris damien
chris edwin
chris lisa mayur
chris lisa mayur geetha
chris lisa
chris
Could someone please guide me on how to achieve this transformation using Power Query? Any insights, suggestions, or sample code would be greatly appreciated.
Solved! Go to Solution.
Hi
= Table.Distinct(
Table.FromRows(
List.TransformMany(
Table.ToRows(Source),
each {1..4},
(x,y) => List.FirstN(x,y) & List.Repeat({null}, 4-y)
),
type table [L0 = text, L1 = text, L2 = text, L3 = text])
)
Stéphane
Hi
= Table.Distinct(
Table.FromRows(
List.TransformMany(
Table.ToRows(Source),
each {1..4},
(x,y) => List.FirstN(x,y) & List.Repeat({null}, 4-y)
),
type table [L0 = text, L1 = text, L2 = text, L3 = text])
)
Stéphane