Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be 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

Reply
gancw1
Resolver I
Resolver I

Pivoting non-numeric value

How do I transform a table in this format 

 

CompanyTeamMemberStart DateEnd Date
ASalesDavid1 Jan 20222 Jan 2022
AFinanceAmy2 Jan 20225 Jan 2022
BSalesJohn5 Oct 20227 Oct 2022
BFinanceLyn7 Oct 20228 Oct 2022

 

to this format in Power Query ?

 

CompanySalesFinanceSales Start DateSales End DateFinance Start DateFinance End Date
ADavidAmy1 Jan 20222 Jan 20222 Jan 20225 Jan 2022
BJohnLyn2 Jan 20225 Jan 20227 Oct 20228 Oct 2022
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@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"
Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@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"
Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Thanks. Can you explain how it works ?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.