Forum Discussion

PiyushBQ's avatar
PiyushBQ
Icon for Helper I rankHelper I
6 years ago
Solved

Converting List to Meaningful Data

Hi, I have this table:   Date A B C 5-Jan 9 43 133 6-Jan 2 48 118 Date B D A 7-Jan 17 1050 7 8-Jan 14 1257 4   The desired output looks like the followin...
  • v-juanli-msft's avatar
    6 years ago

    Hi PiyushBQ 

    Copy and paste my query in advanced editor

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtX1SsxT0lGyBGITYyBhaGysFKsTrWQGlTACSViAJAwtwBIuiSWpQK4TELsAsSNY0Byq2tAcRBiYGgApc7CMBUzGBEQYmYIUmCjFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, A = _t, B = _t, C = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type text}, {"A", type text}, {"B", type text}, {"C", type text}}),
        #"Demoted Headers" = Table.DemoteHeaders(#"Changed Type"),
        #"Changed Type1" = Table.TransformColumnTypes(#"Demoted Headers",{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}}),
        #"Added Index" = Table.AddIndexColumn(#"Changed Type1", "Index", 1, 1),
        #"Added Conditional Column" = Table.AddColumn(#"Added Index", "Custom", each if [Column1] = "Date" then [Index] else null),
        #"Filled Down" = Table.FillDown(#"Added Conditional Column",{"Custom"}),
        #"Removed Columns" = Table.RemoveColumns(#"Filled Down",{"Index"}),
        #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Column1", "Custom"}, "Attribute", "Value"),
        #"Sorted Rows" = Table.Sort(#"Unpivoted Columns",{{"Custom", Order.Ascending}, {"Attribute", Order.Ascending}, {"Value", Order.Descending}}),
        #"Duplicated Column" = Table.DuplicateColumn(#"Sorted Rows", "Value", "Value - Copy"),
        #"Changed Type2" = Table.TransformColumnTypes(#"Duplicated Column",{{"Value - Copy", type number}}),
        #"Replaced Errors" = Table.ReplaceErrorValues(#"Changed Type2", {{"Value - Copy", 9999}}),
        #"Added Conditional Column1" = Table.AddColumn(#"Replaced Errors", "Custom.1", each if [#"Value - Copy"] = 9999 then [Value] else null),
        #"Filled Down1" = Table.FillDown(#"Added Conditional Column1",{"Custom.1"}),
        #"Filtered Rows" = Table.SelectRows(#"Filled Down1", each [#"Value - Copy"] <> 9999),
        #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows",{"Custom", "Attribute", "Value - Copy"}),
        #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns1",{"Column1", "Custom.1", "Value"}),
        #"Sorted Rows1" = Table.Sort(#"Reordered Columns",{{"Column1", Order.Ascending}, {"Custom.1", Order.Ascending}})
    in
        #"Sorted Rows1"

    Best Regards
    Maggie
    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.