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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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"

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"

Thanks. Can you explain how it works ?

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.