cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
gancw1
Helper III
Helper III

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"


!! Microsoft Fabric !!
Microsoft Power BI Learning Resources, 2023 !!
Learn Power BI - Full Course with Dec-2022, with Window, Index, Offset, 100+ Topics !!
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!

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"


!! Microsoft Fabric !!
Microsoft Power BI Learning Resources, 2023 !!
Learn Power BI - Full Course with Dec-2022, with Window, Index, Offset, 100+ Topics !!
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!

Thanks. Can you explain how it works ?

Helpful resources

Announcements
May 2023 update

Power BI May 2023 Update

Find out more about the May 2023 update.

Submit your Data Story

Data Stories Gallery

Share your Data Story with the Community in the Data Stories Gallery.

Top Solution Authors