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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Chris_71720_PBi
Regular Visitor

Transformation of Data (Pivot)

Hello Team

Need you help on how to transform data 

Below is my Data 

AssessmentIdStrategicRiskTitleVariableTitleMetricTitleScoreValue
4Access to Capital and Liquidity XImpact2
4Access to Capital and Liquidity YLikelihood2
4Access to Capital and Liquidity ZInherent4
4Business Continuity FailureXImpact4
4Business Continuity FailureYLikelihood5
4Business Continuity FailureZInherent20
4Business Continuity RiskXImpact5
4Business Continuity RiskYLikelihood6
4Business Continuity RiskZInherent30
4Compliance RiskXImpact1
4Compliance RiskYLikelihood3
4Compliance RiskZInherent3
5Business Continuity RiskXImpact3
5Business Continuity RiskYLikelihood3
5Business Continuity RiskZInherent9
5Compliance RiskXImpact4
5Compliance RiskYLikelihood2
5Compliance RiskZInherent8

 

And this the out come I need

 

AssessmentIdStrategicRiskTitleImpact (X)Likelihood (Y)Inherent (Z)
4Access to Capital and Liquidity 224
4Business Continuity Failure4520
4Business Continuity Risk5630
4Compliance Risk133
5Business Continuity Risk339
5Compliance Risk428
1 ACCEPTED SOLUTION
Nathaniel_C
Community Champion
Community Champion

Hi @Chris_71720_PBi ,

Here you go!
Steps in Power Query: reorder columns so that you can combine them with the XYZ at the end, next merge the columns with a space and "(", next add a suffix ")" , finally pivot using Score Value, and in the advanced - do not aggregate.

image.png

Paste the code below into the Advanced Editor

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lZI9C8IwEED/SsjsoP0QHbUgCJ2c1NIhtIEebZPaJIP/3kSkQtqm6XCQ4T3ucSTLcIQ3+FQUVAgkOUpIB5I0iLASpfBSUIJ8I43c9VzbjhRSPwKcb7zNh54UatpAxXm51n6avayiPWVmczS4ZyWAGTvhTAJThr8QaFRP7VxfaVQae4pWZLB1ejcQtZ3o3vQzRn17H8uKC/9xCW+7Bggr6GTTzgGOUkIHbBd80XjFdbyMmaQFy2o7Ds7CcSIHOPPjp2Er4IDz/AM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [AssessmentId = _t, StrategicRiskTitle = _t, VariableTitle = _t, MetricTitle = _t, ScoreValue = _t]),
    #"Reordered Columns" = Table.ReorderColumns(Source,{"AssessmentId", "StrategicRiskTitle", "MetricTitle", "VariableTitle", "ScoreValue"}),
    #"Merged Columns" = Table.CombineColumns(#"Reordered Columns",{"MetricTitle", "VariableTitle"},Combiner.CombineTextByDelimiter(" (", QuoteStyle.None),"Merged"),
    #"Added Suffix" = Table.TransformColumns(#"Merged Columns", {{"Merged", each _ & ")", type text}}),
    #"Pivoted Column" = Table.Pivot(#"Added Suffix", List.Distinct(#"Added Suffix"[Merged]), "Merged", "ScoreValue")
in
    #"Pivoted Column"

If you have any questions as to how to do the specific steps, pls let me know.
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

1 REPLY 1
Nathaniel_C
Community Champion
Community Champion

Hi @Chris_71720_PBi ,

Here you go!
Steps in Power Query: reorder columns so that you can combine them with the XYZ at the end, next merge the columns with a space and "(", next add a suffix ")" , finally pivot using Score Value, and in the advanced - do not aggregate.

image.png

Paste the code below into the Advanced Editor

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lZI9C8IwEED/SsjsoP0QHbUgCJ2c1NIhtIEebZPaJIP/3kSkQtqm6XCQ4T3ucSTLcIQ3+FQUVAgkOUpIB5I0iLASpfBSUIJ8I43c9VzbjhRSPwKcb7zNh54UatpAxXm51n6avayiPWVmczS4ZyWAGTvhTAJThr8QaFRP7VxfaVQae4pWZLB1ejcQtZ3o3vQzRn17H8uKC/9xCW+7Bggr6GTTzgGOUkIHbBd80XjFdbyMmaQFy2o7Ds7CcSIHOPPjp2Er4IDz/AM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [AssessmentId = _t, StrategicRiskTitle = _t, VariableTitle = _t, MetricTitle = _t, ScoreValue = _t]),
    #"Reordered Columns" = Table.ReorderColumns(Source,{"AssessmentId", "StrategicRiskTitle", "MetricTitle", "VariableTitle", "ScoreValue"}),
    #"Merged Columns" = Table.CombineColumns(#"Reordered Columns",{"MetricTitle", "VariableTitle"},Combiner.CombineTextByDelimiter(" (", QuoteStyle.None),"Merged"),
    #"Added Suffix" = Table.TransformColumns(#"Merged Columns", {{"Merged", each _ & ")", type text}}),
    #"Pivoted Column" = Table.Pivot(#"Added Suffix", List.Distinct(#"Added Suffix"[Merged]), "Merged", "ScoreValue")
in
    #"Pivoted Column"

If you have any questions as to how to do the specific steps, pls let me know.
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.