Forum Discussion

lotus22's avatar
lotus22
Helper III
6 years ago
Solved

Transform rows to columns

  How can I transform rows 1-6 into columns so that I can correlate them with the plant.   I would like to see Actual/Forecast, Month, Year to date, Account#, and Expense in columns 2,3,4,5,...
  • lbendlin's avatar
    6 years ago

    First step - eliminate the blanks in the header.

     

    TypeActualActualActualActualForecastForecastForecastForecast
    MonthJunJunJunJunJulyAugustSeptemberOctober
    Year20202020202020202020202020202020
    MeasureYear to DateYear to DateYear to DateYear to DateYear to DateYear to DateYear to DateYear to Date
    AccountAccount 1Account 2Account 3Account 4Account 1Account 2Account 3Account 4
    ExpenseExpense 1Expense 2Expense 3Expense 4Expense 1Expense 2Expense 3Expense 4
    Plant 1000002,253.0000
    Plant 20561,411.00451,152.00005,254.0004,451.00
    Plant 39,774.6045,411.000009,883.1045,111.000
    Plant 45,624.3000000220
    Plant 500000000
    Plant 6025,200.0000192.9004,551.00
    Plant 75,000.0048,636.1052,614.0004,356.6044,141.0000
    Plant 83,200.0020,194.8052,561.003,547.509,941.5008,145.000

     

    Then you can start transposing and unpivoting

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("vVHBSsQwEP2VpechJJNJ2h4X1IMgCnqRsodagh5qu2xTcP/eJG1Ndukqe/GQ9s3w5uW9SVVlL8e9ySDbNnas29/BXX8wTT3Yv+EOquyh7+yHa96P3YVve/Tq4/sYhp/N3prPN3Nw+LGxvUde59XUvoUc+fW/YMTUw3jwIb3Uxvabm9r+Y+k9bJumHzsbthnQRiQYEywTTFfz/V23X3vTDd7GjMLsgjHBMsF0Nd/f9dTWsze+chBQScZjK47g3FNaAAkxkUgJEArTCcdwIhRbBI7ly6jlbZWQ58T0pBIV01NCUUgmZoqIlKhE4T6NxORanpAJz2bUBeJaar2IuFCcn1oUJbIyqQnUedA82OPLJBWgpZ4SKQQtTtYklZ73QSBIrD9D4WoZvSAHURIrZkX3OFNfgqKcqWmLpRNTi1jhtNXPInff", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t, Column9 = _t]),
        #"Transposed Table" = Table.Transpose(Source),
        #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {"Expense", "Account", "Measure", "Year", "Month", "Type"}, "Attribute", "Value")
    in
        #"Unpivoted Other Columns"