Arranging panel data

%3CLINGO-SUB%20id%3D%22lingo-sub-1379948%22%20slang%3D%22en-US%22%3EArranging%20panel%20data%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1379948%22%20slang%3D%22en-US%22%3E%3CP%3EHey%20community!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20really%20appreciate%20some%20help%20with%20an%20excel%20problem%20that%20I'm%20having.%20I%20attached%20an%20excel%20file%20for%20clarification.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20transform%20a%20file%20that%20has%20the%20same%20layout%20as%20the%20example%20file%20but%20with%20thousands%20of%20lines%20into%20panel%20data.%20Meaning%2C%20the%20top%20table%20needs%20to%20be%20tranformed%20into%20the%20bottom%20table%20as%20efficient%20as%20possible%20as%20control%20%2B%20c'ing%20thousands%20of%20lines%20would%20take%20too%20much%20time.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20can%20I%20perform%20this%20task%20as%20efficient%20as%20possible%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1379948%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EBI%20%26amp%3B%20Data%20Analysis%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1542491%22%20slang%3D%22en-US%22%3ERe%3A%20Arranging%20panel%20data%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1542491%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F663314%22%20target%3D%22_blank%22%3E%40Bootje%3C%2FA%3E%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20use%20Power%20Query%20for%20this%20transformation%3C%2FP%3E%3CP%3E1.%20Convert%20your%20Raw%20Data%20in%20Tables%20%26amp%3B%20then%20load%20it%20into%20Power%20Query%20Editor%3C%2FP%3E%3CP%3E2.%20When%20you%20convert%20it%20into%20tables%20uncheck%20my%20table%20has%20headers%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%222020-07-23_23-13-06.png%22%20style%3D%22width%3A%20641px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F207555iE3620FE33529D631%2Fimage-dimensions%2F641x381%3Fv%3D1.0%22%20width%3D%22641%22%20height%3D%22381%22%20title%3D%222020-07-23_23-13-06.png%22%20alt%3D%222020-07-23_23-13-06.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBelow%20are%20the%20step%20from%20the%20Power%20Query%20for%20the%20transformation.%20I%20will%20be%20attaching%20the%20solution%20file%20for%20your%20reference.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3Elet%0A%20%20%20%20Source%20%3D%20Excel.CurrentWorkbook()%7B%5BName%3D%22RawData%22%5D%7D%5BContent%5D%2C%0A%20%20%20%20%23%22Promoted%20Headers%22%20%3D%20Table.PromoteHeaders(Source%2C%20%5BPromoteAllScalars%3Dtrue%5D)%2C%0A%20%20%20%20%23%22Unpivoted%20Other%20Columns%22%20%3D%20Table.UnpivotOtherColumns(%23%22Promoted%20Headers%22%2C%20%7B%22date%22%7D%2C%20%22Attribute%22%2C%20%22Value%22)%2C%0A%20%20%20%20%23%22Split%20Column%20by%20Delimiter%22%20%3D%20Table.SplitColumn(%23%22Unpivoted%20Other%20Columns%22%2C%20%22Attribute%22%2C%20Splitter.SplitTextByDelimiter(%22_%22%2C%20QuoteStyle.Csv)%2C%20%7B%22Attribute.1%22%2C%20%22Attribute.2%22%7D)%2C%0A%20%20%20%20%23%22Removed%20Columns%22%20%3D%20Table.RemoveColumns(%23%22Split%20Column%20by%20Delimiter%22%2C%7B%22Attribute.2%22%7D)%2C%0A%20%20%20%20%23%22Added%20Conditional%20Column%22%20%3D%20Table.AddColumn(%23%22Removed%20Columns%22%2C%20%22company%20id%22%2C%20each%20if%20Text.StartsWith(%5BAttribute.1%5D%2C%20%22company%22)%20then%20%5BValue%5D%20else%20null)%2C%0A%20%20%20%20%23%22Filled%20Down%22%20%3D%20Table.FillDown(%23%22Added%20Conditional%20Column%22%2C%7B%22company%20id%22%7D)%2C%0A%20%20%20%20%23%22Filtered%20Rows%22%20%3D%20Table.SelectRows(%23%22Filled%20Down%22%2C%20each%20not%20Text.StartsWith(%5BAttribute.1%5D%2C%20%22company%22))%2C%0A%20%20%20%20%23%22Changed%20Type%22%20%3D%20Table.TransformColumnTypes(%23%22Filtered%20Rows%22%2C%7B%7B%22date%22%2C%20type%20date%7D%2C%20%7B%22Attribute.1%22%2C%20type%20text%7D%2C%20%7B%22Value%22%2C%20Currency.Type%7D%2C%20%7B%22company%20id%22%2C%20type%20text%7D%7D)%2C%0A%20%20%20%20%23%22Pivoted%20Column%22%20%3D%20Table.Pivot(%23%22Changed%20Type%22%2C%20List.Distinct(%23%22Changed%20Type%22%5BAttribute.1%5D)%2C%20%22Attribute.1%22%2C%20%22Value%22%2C%20List.Sum)%2C%0A%20%20%20%20%23%22Sorted%20Rows%22%20%3D%20Table.Sort(%23%22Pivoted%20Column%22%2C%7B%7B%22company%20id%22%2C%20Order.Ascending%7D%2C%20%7B%22date%22%2C%20Order.Ascending%7D%7D)%0Ain%0A%20%20%20%20%23%22Sorted%20Rows%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ERegards%2C%20Faraz%20Shaikh%20%7C%20MCT%2C%20MIE%2C%20MOS%20Master%2C%20Excel%20Expert%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CEM%3E%3CFONT%20color%3D%22%23808080%22%3EIf%20you%20find%20the%20above%20solution%20resolved%20your%20query%20don't%20forget%20mark%20as%26nbsp%3B%3CSPAN%3EOfficial%2FBest%20Answer%26nbsp%3Bto%20help%20the%20other%20members%20find%20it%20more%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

Hey community!

 

I would really appreciate some help with an excel problem that I'm having. I attached an excel file for clarification.

 

I want to transform a file that has the same layout as the example file but with thousands of lines into panel data. Meaning, the top table needs to be tranformed into the bottom table as efficient as possible as control + c'ing thousands of lines would take too much time. 

 

How can I perform this task as efficient as possible?

 

Thanks in advance!

1 Reply

Hi @Bootje;

 

You can use Power Query for this transformation

1. Convert your Raw Data in Tables & then load it into Power Query Editor

2. When you convert it into tables uncheck my table has headers

 

2020-07-23_23-13-06.png

 

Below are the step from the Power Query for the transformation. I will be attaching the solution file for your reference. 

 

 

let
    Source = Excel.CurrentWorkbook(){[Name="RawData"]}[Content],
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {"date"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter("_", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
    #"Removed Columns" = Table.RemoveColumns(#"Split Column by Delimiter",{"Attribute.2"}),
    #"Added Conditional Column" = Table.AddColumn(#"Removed Columns", "company id", each if Text.StartsWith([Attribute.1], "company") then [Value] else null),
    #"Filled Down" = Table.FillDown(#"Added Conditional Column",{"company id"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each not Text.StartsWith([Attribute.1], "company")),
    #"Changed Type" = Table.TransformColumnTypes(#"Filtered Rows",{{"date", type date}, {"Attribute.1", type text}, {"Value", Currency.Type}, {"company id", type text}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Attribute.1]), "Attribute.1", "Value", List.Sum),
    #"Sorted Rows" = Table.Sort(#"Pivoted Column",{{"company id", Order.Ascending}, {"date", Order.Ascending}})
in
    #"Sorted Rows"

 

 

Regards, Faraz Shaikh | MCT, MIE, MOS Master, Excel Expert

If you find the above solution resolved your query don't forget mark as Official/Best Answer to help the other members find it more