March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
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 ?
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
124 | |
89 | |
84 | |
70 | |
51 |
User | Count |
---|---|
206 | |
143 | |
97 | |
79 | |
68 |