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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Append columns within a table

Hi,

 

I have a table like this: 

 

ID    Forecast1   Forecast2   Forecast3   Actual1   Actual2      Actual3   
1ABCDEF
2GHJKLM

 

And I want to make it like below in Power Query Editor. Is there any way of doing this without having multiple duplicate tables and appending them again.  Thanks for the help!

 

 

ID     Forecast   Actual  End Num   
1AD1
1BE2
1CF3
2GK1
2HL2
2JM3

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

try this. PBIX

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("DcY5DQAgEEVBL7+mAQfchEPBZv3b4BWTjJmigjIKKho6hjyYEptY2Di4eHL/", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, Forecast1 = _t, Forecast2 = _t, Forecast3 = _t, Actual1 = _t, Actual2 = _t, Actual3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Forecast1", type text}, {"Forecast2", type text}, {"Forecast3", type text}, {"Actual1", type text}, {"Actual2", type text}, {"Actual3", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID"}, "Attribute", "Value"),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Unpivoted Columns", "Attribute", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Attribute.1", "Attribute.2"}),
    #"Pivoted Column" = Table.Pivot(#"Split Column by Character Transition", List.Distinct(#"Split Column by Character Transition"[Attribute.1]), "Attribute.1", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"Attribute.2", "End Num"}})
in
    #"Renamed Columns"

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


View solution in original post

2 REPLIES 2

Hi @Anonymous ,

 

try this. PBIX

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("DcY5DQAgEEVBL7+mAQfchEPBZv3b4BWTjJmigjIKKho6hjyYEptY2Di4eHL/", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, Forecast1 = _t, Forecast2 = _t, Forecast3 = _t, Actual1 = _t, Actual2 = _t, Actual3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Forecast1", type text}, {"Forecast2", type text}, {"Forecast3", type text}, {"Actual1", type text}, {"Actual2", type text}, {"Actual3", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID"}, "Attribute", "Value"),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Unpivoted Columns", "Attribute", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Attribute.1", "Attribute.2"}),
    #"Pivoted Column" = Table.Pivot(#"Split Column by Character Transition", List.Distinct(#"Split Column by Character Transition"[Attribute.1]), "Attribute.1", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"Attribute.2", "End Num"}})
in
    #"Renamed Columns"

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


kentyler
Solution Sage
Solution Sage

Can you tell us what the goal is.

This seems like one of those cases where it makes more sense to manipulate the data before you load it into Power BI.

The column of "end numbers" means that you are going to be making 3 passes over the base data, and keeping track of the "number" of the pass.

 

There are M code functions that allow you to create new rows.... but it would be easier to work out if we knew what you were trying to achieve.

 





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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