Forum Discussion

sander448's avatar
sander448
New Member
1 year ago
Solved

Having trouble formatting stacked vertical data horizontally

I am pulling data in from a folder containing financials for individual companies. The dates are in the columns and the financial metrics are in the rows. When I pull the data from the folder into po...
  • Chewdata's avatar
    1 year ago

    Hey!

    The code below will do exactly what you want. It uses the folder connector to catch all the files in the folder. With the function it will then first 'clean' all the tables, before combining them into one table.

    let
        Source = Folder.Files("YOUR FOLDER PATH"),
        #"Added Custom" = Table.AddColumn(Source, "Table", each Excel.Workbook([Content])[Data]{0}),
        fnCleanTable = (vTable as table) =>
        let
            #"Transposed Table" = Table.Transpose(vTable),
            #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
            #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Company name", type text}, {"Date", type text}, {"Reveneus", Int64.Type}, {"Cost of Revenu", Int64.Type}, {"Gross Profit", Int64.Type}}),
            #"Filled Down" = Table.FillDown(#"Changed Type",{"Company name"}),
            #"Changed Type with Locale" = Table.TransformColumnTypes(#"Filled Down", {{"Date", type date}}, "en-US")
        in
            #"Changed Type with Locale",
        invoke_function = Table.AddColumn(#"Added Custom", "CleanTable", each fnCleanTable([Table])),
        #"Removed Other Columns" = Table.SelectColumns(invoke_function,{"CleanTable"}),
        #"Expanded CleanTable" = Table.ExpandTableColumn(#"Removed Other Columns", "CleanTable", {"Company name", "Date", "Reveneus", "Cost of Revenu", "Gross Profit"}, {"Company name", "Date", "Reveneus", "Cost of Revenu", "Gross Profit"})
    in
       #"Expanded CleanTable"