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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
emsrc
Frequent Visitor

Help transforming data

Hi,

I have a table of data that looks like this:

 

Screen Shot 2021-01-07 at 3.28.10 PM.png

I would like to transform the data to look like this:

 

Screen Shot 2021-01-07 at 3.29.02 PM.png

I'd like to do this in Power Query, if possible.

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @emsrc 

Place the following M code in a blank query to see the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0MACTQMLYAEIqxepEKxkBmUZgASMQYWIAIZViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project ID" = _t, #"FY20 Budget" = _t, #"FY20 Actuals" = _t, #"FY21 Budget" = _t, #"FY21 Actuals" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project ID", Int64.Type}, {"FY20 Budget", Int64.Type}, {"FY20 Actuals", Int64.Type}, {"FY21 Budget", Int64.Type}, {"FY21 Actuals", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Project ID"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Columns", "Attribute", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type1","FY","20",Replacer.ReplaceText,{"Attribute.1"}),
    #"Renamed Columns" = Table.RenameColumns(#"Replaced Value",{{"Attribute.1", "Year"}}),
    #"Pivoted Column" = Table.Pivot(#"Renamed Columns", List.Distinct(#"Renamed Columns"[Attribute.2]), "Attribute.2", "Value", List.Sum),
    #"Changed Type2" = Table.TransformColumnTypes(#"Pivoted Column",{{"Year", Int64.Type}})
in
    #"Changed Type2"

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

1 REPLY 1
AlB
Community Champion
Community Champion

Hi @emsrc 

Place the following M code in a blank query to see the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0MACTQMLYAEIqxepEKxkBmUZgASMQYWIAIZViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project ID" = _t, #"FY20 Budget" = _t, #"FY20 Actuals" = _t, #"FY21 Budget" = _t, #"FY21 Actuals" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project ID", Int64.Type}, {"FY20 Budget", Int64.Type}, {"FY20 Actuals", Int64.Type}, {"FY21 Budget", Int64.Type}, {"FY21 Actuals", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Project ID"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Columns", "Attribute", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type1","FY","20",Replacer.ReplaceText,{"Attribute.1"}),
    #"Renamed Columns" = Table.RenameColumns(#"Replaced Value",{{"Attribute.1", "Year"}}),
    #"Pivoted Column" = Table.Pivot(#"Renamed Columns", List.Distinct(#"Renamed Columns"[Attribute.2]), "Attribute.2", "Value", List.Sum),
    #"Changed Type2" = Table.TransformColumnTypes(#"Pivoted Column",{{"Year", Int64.Type}})
in
    #"Changed Type2"

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.