Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
How do I transform a table in this format
Company | Team | Member | Start Date | End Date |
A | Sales | David | 1 Jan 2022 | 2 Jan 2022 |
A | Finance | Amy | 2 Jan 2022 | 5 Jan 2022 |
B | Sales | John | 5 Oct 2022 | 7 Oct 2022 |
B | Finance | Lyn | 7 Oct 2022 | 8 Oct 2022 |
to this format in Power Query ?
Company | Sales | Finance | Sales Start Date | Sales End Date | Finance Start Date | Finance End Date |
A | David | Amy | 1 Jan 2022 | 2 Jan 2022 | 2 Jan 2022 | 5 Jan 2022 |
B | John | Lyn | 2 Jan 2022 | 5 Jan 2022 | 7 Oct 2022 | 8 Oct 2022 |
Solved! Go to Solution.
@gancw1 , Use this code in a blank query in power query
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUQpOzEktBtIuiWWZKUDaUMErMU/ByMDICMgxQnBidSDq3TLzEvOSU4Esx9xKVCU6Sqao6p2QzPfKz8gDq/BPLoEpN0dwYMoRxvtU5qEq0VGyQFIfCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Company = _t, Team = _t, Member = _t, #"Start Date" = _t, #"End Date" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Company", type text}, {"Team", type text}, {"Member", type text}, {"Start Date", type date}, {"End Date", type date}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Company", "Team", "Member"}, "Attribute", "Value"),
#"Duplicated Column" = Table.DuplicateColumn(#"Unpivoted Columns", "Team", "Team - Copy"),
#"Merged Columns" = Table.CombineColumns(#"Duplicated Column",{"Team", "Attribute"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
#"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Merged]), "Merged", "Value"),
#"Pivoted Column1" = Table.Pivot(#"Pivoted Column", List.Distinct(#"Pivoted Column"[#"Team - Copy"]), "Team - Copy", "Member", List.Max),
#"Grouped Rows" = Table.Group(#"Pivoted Column1", {"Company"}, {{"Sales Start Date", each List.Max([Sales Start Date]), type nullable date}, {"Sales End Date", each List.Max([Sales End Date]), type nullable date}, {"Finance Start Date", each List.Max([Finance Start Date]), type nullable date}, {"Finance End Date", each List.Max([Finance End Date]), type nullable date}, {"Finanace", each List.Max([Finance]), type nullable text}, {"Sales", each List.Max([Sales]), type nullable text}})
in
#"Grouped Rows"
@gancw1 , Use this code in a blank query in power query
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUQpOzEktBtIuiWWZKUDaUMErMU/ByMDICMgxQnBidSDq3TLzEvOSU4Esx9xKVCU6Sqao6p2QzPfKz8gDq/BPLoEpN0dwYMoRxvtU5qEq0VGyQFIfCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Company = _t, Team = _t, Member = _t, #"Start Date" = _t, #"End Date" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Company", type text}, {"Team", type text}, {"Member", type text}, {"Start Date", type date}, {"End Date", type date}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Company", "Team", "Member"}, "Attribute", "Value"),
#"Duplicated Column" = Table.DuplicateColumn(#"Unpivoted Columns", "Team", "Team - Copy"),
#"Merged Columns" = Table.CombineColumns(#"Duplicated Column",{"Team", "Attribute"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
#"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Merged]), "Merged", "Value"),
#"Pivoted Column1" = Table.Pivot(#"Pivoted Column", List.Distinct(#"Pivoted Column"[#"Team - Copy"]), "Team - Copy", "Member", List.Max),
#"Grouped Rows" = Table.Group(#"Pivoted Column1", {"Company"}, {{"Sales Start Date", each List.Max([Sales Start Date]), type nullable date}, {"Sales End Date", each List.Max([Sales End Date]), type nullable date}, {"Finance Start Date", each List.Max([Finance Start Date]), type nullable date}, {"Finance End Date", each List.Max([Finance End Date]), type nullable date}, {"Finanace", each List.Max([Finance]), type nullable text}, {"Sales", each List.Max([Sales]), type nullable text}})
in
#"Grouped Rows"
Thanks. Can you explain how it works ?
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
113 | |
94 | |
88 | |
35 | |
32 |
User | Count |
---|---|
153 | |
101 | |
82 | |
63 | |
52 |