Forum Discussion

jgclarke's avatar
jgclarke
New Member
8 years ago
Solved

Flattening Rows Containing Values and Text Dynamically

I have unpivotted / pivotted my data and created a table that grows dynamically (ie: Each new month added  will result in a new "value" column and a new "Notes" column. The table is shown below:   ...
  • MarkS's avatar
    8 years ago

    HI jgclarke,

    Based on the information given I think that your raw data looks like this:

     

    If that is the case then the following will get the data in the shape that you want (Change the Source step to refer to your table)

    let
        Source = Table
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", type text}, {"Customer", type text}, {"Value", type number}, {"Comment", type text}}),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Month", "Customer"}, "Attribute", "Value.1"),
        #"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Custom", each [Attribute]& "-" & [Month]),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Attribute", "Month"}),
        #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Custom]), "Custom", "Value.1")
    in
        #"Pivoted Column"

     

  • jgclarke's avatar
    jgclarke
    8 years ago

    Thank you MarkS

     

    That works 100%. 

     

    I think that I was overcomplicating my code.