Forum Discussion

dmarkie's avatar
dmarkie
Frequent Visitor
4 years ago
Solved

Fill Adjacent Blank Cells

Hello; I am trying to transform a table that has a couple of columns similar to below.  There are hundreds of MasterIDs.  Some MasterID have a corresponding VehID however there are some records/rows...
  • Vijay_A_Verma's avatar
    4 years ago

    See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjY1VdJRMjIyVYrVgfGQmEamOCQIMmFGmpgawCQgTCNDA2IkwLxYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Master ID" = _t, #"Veh ID" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Master ID", Int64.Type}, {"Veh ID", Int64.Type}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"Master ID"}, {{"Temp", each _, type table [Master ID=nullable number, Veh ID=nullable number]}}),
        //Function Start
        fxProcess=(Tbl)=>
            let
                #"Filled Down" = Table.FillDown(Tbl,{"Veh ID"}),
                #"Filled Up" = Table.FillUp(#"Filled Down",{"Veh ID"})
            in
                #"Filled Up",
        //Function ENd
        #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each fxProcess([Temp])),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Master ID", "Temp"}),
        #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Master ID", "Veh ID"}, {"Master ID", "Veh ID"})
    in
        #"Expanded Custom"