Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Allocate correct PO from the Stock Table based on stock availability

Good afternoon!  

I have two tables in Power BI:

1. Stock Table: This table contains details of stock orders, including the Purchase Order (PO) number, the quantity ordered, and the transaction date.

2. Fitted Table: This table tracks the stock that has been fitted, including the call number (which is an identifier for the fitting event), the date it was fitted, and the quantity fitted.

Problem:
I need to link the fitted quantities in the Fittings Table with the correct PO(REFERENCE) from the Stock Table based on stock availability. Specifically:

- When stock is ordered, I want to allocate that stock to the fittings in the same order it was fitted.
- For example, if I order 3 units under a specific PO, I want to assign that PO to the first 3 fitting events (calls) that use this stock.
- Once the stock from that PO is fully allocated, I want to start associating the next fitting events with the next PO that has available stock, and so on.

The common column between the two tables is the PartNumber. Please see example of how the tables look, including just one product:

Stock Table:

PARTNUMBERREFERENCETRANDATEQUANTITY
30CXXXH16964102/01/20241
30CXXXD1780416/04/20241
30CXXXH17111912/06/20242
30CXXXH17112817/06/20247
30CXXXD1783817/06/20242
30CXXXH17111917/06/20242
30CXXXH17114418/06/20241
30CXXXD1783703/07/20246
30CXXXD1783804/07/20241
30CXXXD1783722/07/20242

Fitted Table

CALLNUMBERCALLDATEPARTNUMBERPARTFIT
16138622/03/202430CXX1
14978512/04/202430CXX1
23154128/05/202430CXX1
14352428/05/202430CXX1
17862428/05/202430CXX1
45536928/05/202430CXX1
32270529/05/202430CXX1
33908829/05/202430CXX1
19952229/05/202430CXX1
19846412/06/202430CXX0
50035421/06/202430CXX1
47953521/06/202430CXX1
24447121/06/202430CXX1
29274021/06/202430CXX1
29618821/06/202430CXX1
14453321/06/202430CXX1
48436121/06/202430CXX1
19962528/06/202430CXX1
20026401/07/202430CXX1
24721903/07/202430CXX1
35620803/07/202430CXX1
48573805/07/202430CXX1

Expected Result

CALLNUMBERCALLDATEPARTNUMBERPARTFITREFERENCE
16138622/03/202430CXX1XH169641
14978512/04/202430CXX1XD17804
23154128/05/202430CXX1XH171119
14352428/05/202430CXX1XH171119
17862428/05/202430CXX1XH171128
45536928/05/202430CXX1XH171128
32270529/05/202430CXX1XH171128
33908829/05/202430CXX1XH171128
19952229/05/202430CXX1XH171128
19846412/06/202430CXX0 
50035421/06/202430CXX1XH171128
47953521/06/202430CXX1XH171128
24447121/06/202430CXX1XD17838
29274021/06/202430CXX1XD17838
29618821/06/202430CXX1XH171119
14453321/06/202430CXX1XH171119
48436121/06/202430CXX1XH171144
19962528/06/202430CXX1XD17837
20026401/07/202430CXX1XD17837
24721903/07/202430CXX1XD17837
35620803/07/202430CXX1XD17837
48573805/07/202430CXX1XD17837

 

I have already tried this in DAX, creating 2 calculated Columns, Cumulative Stock and Cummulative Fitted and a column for the Allocated PO, however I don't get accurate allocation and the POs are wierdly distributed.

 

I am wondering maybe there are ways to achieve this in Power Query?

 

I would really appreciate your help.

Thanks in advance

6 Replies

  •  

    You have multiple references for the same TRANDATE. Neither Power Query nor Power BI guarantees a sort order. You must provide your own index column.

     

    What should happen when a fitting is attempted while no stock is available?

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you lbendlin. Yes, I have to use an index column. And in my calculation in Dax I am using that, but still don't get the correct allocation.

       

      Good point that I have to deal with the situation there is no stock..

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

        Please provide sample data that fully covers your issue.
        Please show the expected outcome based on the sample data you provided.