Forum Discussion

ngocrin1's avatar
ngocrin1
Frequent Visitor
3 years ago
Solved

Get the value base on lastest date condition

Hi Everyone,

I have order table and delivery table and need to get the exact value (Delivery date & Order ID) as below:

I dont know the way to solve it in Power Query. Has everyone help me?

  • Hi ngocrin1 

     

    Do you have an OrderID column in Delivery table? If so, you can use Merge queries feature. Select both OrderID and CustomerKey as matching columns. This will match the corresponding DeliveryDate based on OrderID and CustomerKey fast and easily. 

     

    If you don't have OrderID column in Delivery table, you can still use Merge queries feature but select only CustomerKey as matching column. 

    Then add a custom column with below code 

    let vOrderDate = [OrderDate] in List.Min(Table.SelectRows([Delivery Table], each [DeliveryDate] >= vOrderDate)[DeliveryDate])

     

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

4 Replies

  • Syk's avatar
    Syk
    Resident Rockstar

    You will need the orderID in your delivery table as well.. Otherwise there's no way to tell which order the delivery date is referencing.

    • ngocrin1's avatar
      ngocrin1
      Frequent Visitor

      Tks Syk . I think if we can add a column with the date range between the day of 2 orders we can lookup exactly the order. But I dont know to do it.

       

      • v-jingzhang's avatar
        v-jingzhang
        Community Support

        Hi ngocrin1 

         

        Do you have an OrderID column in Delivery table? If so, you can use Merge queries feature. Select both OrderID and CustomerKey as matching columns. This will match the corresponding DeliveryDate based on OrderID and CustomerKey fast and easily. 

         

        If you don't have OrderID column in Delivery table, you can still use Merge queries feature but select only CustomerKey as matching column. 

        Then add a custom column with below code 

        let vOrderDate = [OrderDate] in List.Min(Table.SelectRows([Delivery Table], each [DeliveryDate] >= vOrderDate)[DeliveryDate])

         

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