Forum Discussion

mddistributor1's avatar
mddistributor1
Regular Visitor
4 years ago

Power Query - Data manipulation

I have data setup like the below table. Every time something is received the system creates a dash that is one higher than the prior one which shows everything that is yet to be received. I'm trying to calculate backorders by month, but I need the data setup differently. I could use some help on how this might be possible. 

VendorIDPoNumPODatePO AmountReceived amountReceived Date
11234/2/2022$1,000  
1123-14/2/2022$1,000$1004/8/2022
1123-24/2/2022$1,000$2005/25/2022
1123-34/2/2022$1,000$7006/3/2022
11255/6/2022$1,000  
1125-15/6/2022$1,000$7005/23/2022
1125-25/6/2022$1,000$2007/6/2022

 

I'd like to get to the table below. You'll notice on PO 125 that the same amount is in May and June because the backorder amount hasn't changed for June, but there is no received date for that month in the original data. 

VendorIDPoNumMonth EndBackorder Amount (PO Amount - Received)
1123-14/30/2022$900
1123-25/31/2022$700
1123-36/30/2022$0
1125-15/31/2022$300
1125-16/31/2022$300
1125-27/31/2022$100

6 Replies

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Community Champion

    = #table({"VendorID","PoNum","Month End","Backorder Amount"},List.TransformMany(Table.Group(Source,{"VendorID","PoNum"},{"n",each Table.ToRows(Table.Sort(_,"Received Date"))},1,(x,y)=>let fx=(x)=>Text.Format("#[VendorID]-#[PoNum]",x&[PoNum=Text.BeforeDelimiter(Text.From(x[PoNum]),"-")]) in Value.Compare(fx(x),fx(y)))[n],each List.Accumulate(List.Skip(_),{{},_{0}{3}},(x,y)=>{x{0}&{List.FirstN(y,2)&{Date.EndOfMonth(Date.From(y{5})),x{1}-y{4}}},x{1}-y{4}}){0},(x,y)=>y))

     

    • mddistributor1's avatar
      mddistributor1
      Regular Visitor

      This looks great, but I might need a little more explaination on this to completely understand what's going on. 

  • CNENFRNL's avatar
    CNENFRNL
    Community Champion

    Wierd to use PQ to solve such a question whereas DAX is designed to come into play in such a scenario. A DAX solution is way more concise and elegant.

     

    For fun only, showcase of powerful worksheet formula,

    • mddistributor1's avatar
      mddistributor1
      Regular Visitor

      This is an awesome setup. I wouldn't have come up with that. Do you have any way to get that extra date in there? Because June doesn't have anything showing for backorders even though there was $300 in backorders that month. This was originally why I was thinking power query because I wanted the actual data to have something for each date. If that is possible in DAX I'd love to know how to do it.