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 where the VehID is missing.  How might i fill these blank values with the same VehID value?  I've tried using Fill in various ways but with no luck.  

Thanks in advance

Dave

 

Master IDVeh ID
355225
355 
355255
355 
355 
355 
355 
355225
450 
450210
450 
450210
450210
  • 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"

     

2 Replies

  • Vijay_A_Verma's avatar
    Vijay_A_Verma
    Most Valuable Professional

    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"

     

    • dmarkie's avatar
      dmarkie
      Frequent Visitor

      Thank you Vijay for your answer.  I was able to sole this vai transforming the data in excel prior to the bi import.

       

      Thanks again.

      Dave