Forum Discussion

erpeff's avatar
erpeff
Frequent Visitor
3 years ago
Solved

Fill matrix blank cells with previous value

I have my matrix like this 

 

My desired result is to fill the blank values with preceding non zero value.

 

 

  •  Hi , erpeff 

    For your need , you can use this M language in "Power Query Editor":

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZBLDoAgDETv0jUL+wHhEl6AcAbvv5MKUcTGmMym9AEzkzNsO4KDJiQWf02jAhSnLE3nIsLjTApg7DSbb91qlJhL5pmznc1UeG+8IKGBrvbHtQXsOYnpDFXNtCvxl4f0TWnNKXUWl4dVP6dkQtGGWKqXUg4=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [No_test = _t, #"11-12" = _t, #"12-13" = _t, #"13-14" = _t, #"14-15" = _t, #"15-16" = _t, #"16-17" = _t, #"17-18" = _t, #"19-20" = _t, #"20-21" = _t, #"21-22" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,List.Zip({List.Skip(Table.ColumnNames(Source)),List.Repeat({type text},List.Count( List.Skip(Table.ColumnNames(Source))))})),
        Custom1 = #"Changed Type",
        #"Added Custom" = Table.TransformColumns(Table.AddColumn(Custom1, "Custom", (x)=> Table.FillDown(Table.TransformColumnTypes(Table.Unpivot(Table.FromRecords({x}),List.Skip(Table.ColumnNames(Source)),"test","value"),{"value",type number}),{"value"}) )  ,{"Custom",(x)=>Table.Pivot(x, List.Distinct(x[test]), "test", "value")}                ),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"No_test", "11-12", "12-13", "13-14", "14-15", "15-16", "16-17", "17-18", "19-20", "20-21", "21-22"}),
        #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"No_test", "11-12", "12-13", "13-14", "14-15", "15-16", "16-17", "17-18", "19-20", "20-21", "21-22"}, {"No_test", "11-12", "12-13", "13-14", "14-15", "15-16", "16-17", "17-18", "19-20", "20-21", "21-22"}),
        Custom2 = Table.TransformColumnTypes(#"Expanded Custom",List.Zip({List.Skip(Table.ColumnNames(Source)),List.Repeat({type number},List.Count( List.Skip(Table.ColumnNames(Source))))}))
    in
        Custom2

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

     

1 Reply

  •  Hi , erpeff 

    For your need , you can use this M language in "Power Query Editor":

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZBLDoAgDETv0jUL+wHhEl6AcAbvv5MKUcTGmMym9AEzkzNsO4KDJiQWf02jAhSnLE3nIsLjTApg7DSbb91qlJhL5pmznc1UeG+8IKGBrvbHtQXsOYnpDFXNtCvxl4f0TWnNKXUWl4dVP6dkQtGGWKqXUg4=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [No_test = _t, #"11-12" = _t, #"12-13" = _t, #"13-14" = _t, #"14-15" = _t, #"15-16" = _t, #"16-17" = _t, #"17-18" = _t, #"19-20" = _t, #"20-21" = _t, #"21-22" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,List.Zip({List.Skip(Table.ColumnNames(Source)),List.Repeat({type text},List.Count( List.Skip(Table.ColumnNames(Source))))})),
        Custom1 = #"Changed Type",
        #"Added Custom" = Table.TransformColumns(Table.AddColumn(Custom1, "Custom", (x)=> Table.FillDown(Table.TransformColumnTypes(Table.Unpivot(Table.FromRecords({x}),List.Skip(Table.ColumnNames(Source)),"test","value"),{"value",type number}),{"value"}) )  ,{"Custom",(x)=>Table.Pivot(x, List.Distinct(x[test]), "test", "value")}                ),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"No_test", "11-12", "12-13", "13-14", "14-15", "15-16", "16-17", "17-18", "19-20", "20-21", "21-22"}),
        #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"No_test", "11-12", "12-13", "13-14", "14-15", "15-16", "16-17", "17-18", "19-20", "20-21", "21-22"}, {"No_test", "11-12", "12-13", "13-14", "14-15", "15-16", "16-17", "17-18", "19-20", "20-21", "21-22"}),
        Custom2 = Table.TransformColumnTypes(#"Expanded Custom",List.Zip({List.Skip(Table.ColumnNames(Source)),List.Repeat({type number},List.Count( List.Skip(Table.ColumnNames(Source))))}))
    in
        Custom2

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly