Forum Discussion

hpares85's avatar
hpares85
New Member
3 years ago
Solved

Date Slot allocation based on slot available and ETA Date

Hi All, I have 2 table. 1 table is my warehouses daily available slot to receive goods. Another table is the goods ETA at port. We already preplanned which goods is to which warehouse. But I need a ...
  • v-jingzhang's avatar
    3 years ago

    Hi hpares85 

     

    You can create a query with below M code. I have attached the sample file at bottom for your reference. 

    let
        Source = Table.NestedJoin(#"GOODS ETA TABLE", {"PLANNED WAREHOUSE"}, #"TIME SLOT TABLE", {"WAREHOUSE"}, "TIME SLOT TABLE", JoinKind.LeftOuter),
        #"Added Custom" = Table.AddColumn(Source, "Custom", each let __ETA = [ETA] in Table.FirstN(Table.Sort(Table.SelectRows([TIME SLOT TABLE], each [TIME SLOT] > __ETA), {{"TIME SLOT", Order.Ascending}}),1)),
        #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"GOODS", "ETA", "Custom"}),
        #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"TIME SLOT", "WAREHOUSE"}, {"TIME SLOT", "WAREHOUSE"}),
        #"Filtered Rows" = Table.SelectRows(#"Expanded Custom", each ([WAREHOUSE] <> null)),
        #"Reordered Columns" = Table.ReorderColumns(#"Filtered Rows",{"GOODS", "ETA", "WAREHOUSE", "TIME SLOT"})
    in
        #"Reordered Columns"

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it. Highly appreciate your Kudos!