Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Replacing null values with the most recent per category

Hello,

 

I have the following product table. The custom column assigns with Power Query the same values for quantity, and replaces null with the most recent value for each Product code, when it's available. Otherwise, the result is null. I tried using column from examples, but there is no solution. Any ideas?

 

Thank you

 

 

Product CodeDate                     Quantity     Custom Column               
ABC1231/20/202111
BED1232/15/202122
BED2342/20/202122
CED2343/20/202111
EFG6774/1/202133
EFG6774/5/2021null3
EFG6774/7/202122
HFJ1235/1/2021nullnull
HFJ1235/4/202111
UIG8885/8/202111
UIG8885/12/2021null1
UIG8885/20/202122
  • Fowmy's avatar
    Fowmy
    4 years ago

    Anonymous 


    after passing the code, click OK, then remove the word "each" at the beginning 

6 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous 

     

    I am not a fan of example column, it looks like a Fill Down, you can try this way

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc87DoAgDAbgu3QmwRYUVh/42p2INzBu3l+FgKAx6UDzpX+LtVA3LZIABsipuIrwfsPKLDSm80Qcy0AUiIR09Ex5agOJT6Dph0qpq5Ucg4i3xE37sW1vVPmusZ/9heUTGMcSlPkdyzRorZ3oX0H6JCaa/Xo9AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Product Code" = _t, Date = _t, Quantity = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Quantity", Int64.Type}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"Product Code"}, {{"allrows", each _, type table }}),
        #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.FillDown([allrows],{"Quantity"})),
        #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
        #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Product Code", "Date", "Quantity"})
    in
        #"Expanded Custom"

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Fowmy 

       

      Thank you for your reply! For some reason the result in my end is a function for each row, not a value.

       

      I checked the format of each column and looks fine. Any ideas?

       

      Thank you

      • Fowmy's avatar
        Fowmy
        Icon for Super User rankSuper User

        Anonymous 


        after passing the code, click OK, then remove the word "each" at the beginning