Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
learner03
Post Partisan
Post Partisan

Estimated Delivery date based on cumulative count

I have 2 tables-

1) Open Purchase Order- this table shows when are the items arriving in the warehouse based on ETA W/H date. 

DateDocument NumberShipment HeaderItem CodeETA W/HQuantity
5/01/2022230707SHIP3909120285/01/20225490
5/01/2022230707SHIP3909120285/01/2022126
6/01/2022230722SHIP3889109324/01/202219000
6/01/2022230722SHIP3889109324/01/202225000
6/01/2022230722SHIP3889109324/01/202219800
24/01/2022230842SHIP38981208524/01/20225800
24/01/2022230842SHIP38981208524/01/20222000
28/07/2021229160SHIP393315071/02/20226125
19/08/2021229417SHIP3905120858/02/20221000
19/08/2021229417SHIP3905120858/02/20228000
25/08/2021229479SHIP40141527514/02/2022920
25/08/2021229479SHIP40141528114/02/20221500
25/08/2021229479SHIP40141527514/02/202280
6/09/2021229601SHIP39351527515/02/2022920
6/09/2021229601SHIP4012152811/03/20221500
6/09/2021229601 1527515/02/20225360
6/09/2021229601 1528115/02/20223240
14/09/2021229672SHIP4012152751/03/20224000
14/09/2021229672SHIP4012152811/03/20223060
15/09/2021229680SHIP3991109316/02/20225200
20/09/2021229732 1202825/02/202211214
19/10/2021229962SHIP3991109316/02/202210000
19/10/2021229967 1527516/02/20224040
19/10/2021229967 1528116/02/20222940
21/10/2021230009 180018/02/2022500
19/08/2021229417 1208517/03/20229000
20/09/2021229732 1202818/03/202211520
19/10/2021229962 109316/03/20224800
19/10/2021229964 1208516/03/20226000
19/10/2021229971SHIP4012152751/03/20224040
19/10/2021229971SHIP4012152811/03/20222940
9/11/2021230135 152819/03/20221890
9/11/2021230136 135169/03/2022144
9/11/2021230137 152819/03/20222910
18/11/2021230254SHIP40191567319/02/2022460
18/11/2021230254 1567318/03/202240
25/11/2021230313 109325/03/202225800
25/11/2021230324 180025/03/20221200
30/11/2021230365 109330/03/202210000
30/11/2021230371 1527530/03/20222080
30/11/2021230371 1528130/03/20223060
25/11/2021230309 1202815/04/202224012
25/11/2021230313 109314/04/202225800
25/11/2021230320 1208515/04/20228020
25/11/2021230325 1528115/04/20223000
25/11/2021230326 1528125/04/20223270
25/11/2021230326 1527525/04/20222720
25/11/2021230326 180025/04/20221200
3/12/2021230401 152752/04/20225000
6/12/2021230426 15075/04/202212500
14/12/2021230530 150713/04/202217250
14/12/2021230535 180013/04/20223000
12/01/2022230761 109312/05/202236000
12/01/2022230763 1208512/05/202210000
12/01/2022230767 150712/05/20229000
13/01/2022230780 180013/05/20221600
13/01/2022230780 1527513/05/20221520
13/01/2022230780 1528113/05/20223000
13/01/2022230781 1528113/05/2022960

 

2) Back Orders- This table shows the quantity on back orders for the items based on Sales order create date.

DatePO#Sales Order #Item CodeOrdered QtyInvoiced Qty% DeliveredBackorder Qty
7/12/202195260SO003084141093700000.00%7000
10/12/202195375SO003086381093480000.00%4800
20/12/202195590SO00309028109360000.00%600
20/12/202195599SO00309032109380000.00%800
21/12/202195541SO0030907810934000280070.00%1200
5/01/202295609SO003092931093300000.00%3000
19/01/202295755SO003097261093480000.00%4800
19/01/202295757SO00309727109360000.00%600
21/01/202295781SO003098231093300000.00%3000
21/10/202194602SO0030631212028180000.00%1800
21/10/202194598SO003063201202849864972100.00%14
24/11/202195053SO00307834120284000.00%40
8/01/202295618SO00309389120281000800.00%10008
8/01/202295622SO0030939012028350000.00%3500
21/10/202194598SO00306320120851900174092.00%160
8/01/202295618SO0030938912085391000.00%3910
21/10/202194598SO0030632015072500125050.00%1250
29/10/202194672SO00306637150712500.00%125
29/10/202194673SO00306642150737500.00%375
11/11/202194820SO00307164150725000.00%250
24/11/202195057SO003078261507150000.00%1500
24/11/202195053SO00307834150750000.00%500
1/12/202195201SO003081281507125000.00%1250
3/12/202195230SO003082931507300000.00%3000
20/12/202195599SO003090321507125000.00%1250
5/01/202295610SO003092921507125000.00%1250
8/01/202295618SO003093891507250000.00%2500

I need another column in the back order table to calculate Estimated time of delivary based on the below calculation-

for example- if we take Item code "1507", 6125 Qty is arriving at 1st Feb 2022 (from open PO table), then when we see item "1507" in back order table and see the Back order qty column, this much quantity can be fulfilled for the dates between 21/10/2021 to 1/12/2021 as sum of the quantities for this duration will be 5250 (1250+125+375+250+1500+500+1250) and after than if we take another line for same product, it is 3000 and this will exceed 6125. So the estimated delivery date will be +10 working days from ETA W/H date. So if ETA W/H for this product is 1/2/2022, then The estimated delivery date will be approx 12/02/2022. The rest of the quantity for item code 1507 will be fulfilled by same process when another PO for 1507 arrives in the warehouse. 

 

This mechanism should go for all the products.

hope this makes sense.

@Samarth_18 @amitchandak  @Anonymous @ryan_mayu @parry2k @AlexisOlson 

1 ACCEPTED SOLUTION

@learner03 OK, I simplified the equation and was able to eliminate the GENERATESERIES. Not sure why I didn't do it this way the first time. Try this one:

FIFO 2 = 
    VAR __DaysToFulfill = 10
    VAR __ItemCode = [Item Code]
    VAR __Date = [Date]
    VAR __QtyToFulfill = SUMX(FILTER('BackOrders',[Item Code] = __ItemCode && [Date] <= __Date),[Backorder Qty])
    VAR __Table = FILTER('OpenPurchaseOrders',[Item Code] = __ItemCode)
    VAR __Table1 = 
        ADDCOLUMNS(
            ADDCOLUMNS(__Table,"__tqty",SUMX(FILTER(__Table,[ETA W/H] <= EARLIER([ETA W/H])),[Quantity])),
            "__LoopCounter",[__tqty] - __QtyToFulfill
        )
    VAR __TargetDate = MINX(FILTER(__Table1, [__LoopCounter] >= 0),[ETA W/H])
    VAR __FulfillmentDate = IF(__TargetDate = BLANK(),BLANK(),__TargetDate+__DaysToFulfill) 
RETURN
    __FulfillmentDate

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

18 REPLIES 18
Greg_Deckler
Community Champion
Community Champion

@learner03 I believe you want something like the following assuming FIFO for the back oders. PBIX is attached below signature, you can ignore Table2 and TableA, that was somebody else's problem. Basically, a standard DAX while loop.

Column = 
    VAR __DaysToFulfill = 10
    VAR __ItemCode = [Item Code]
    VAR __Date = [Date]
    VAR __QtyToFulfill = SUMX(FILTER('BackOrders',[Item Code] = __ItemCode && [Date] <= __Date),[Backorder Qty])
    VAR __Table = 
        ADDCOLUMNS(
            SELECTCOLUMNS(
                FILTER(ALL('OpenPurchaseOrders'),[Item Code] = __ItemCode),
                "__date",'OpenPurchaseOrders'[ETA W/H],
                "__qty",'OpenPurchaseOrders'[Quantity]
            ),
            "__LoopCounter",[__qty] - __QtyToFulfill
        )
    VAR __TargetDate = MINX(FILTER(__Table, [__LoopCounter] >= 0),[__date])
    VAR __FulfillmentDate = IF(__TargetDate = BLANK(),BLANK(),__TargetDate+__DaysToFulfill) 
RETURN
    __FulfillmentDate

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

Another example is in the working86.pbix that you have attached.

If I look at item code 1507 in both the files-

The line in the new column where it givs 11/01/2022 as result is coming correctly and 15/04/2022,but after that it does not populates the dates correctly-

akapoor03_0-1643758950743.png

In open Purchase order table, if I see same item code 1507, I can see that on 5th April 12,500 Quantity is coming in Warehouse, so in back order table, in the new coloumn where it says 24/04/2022, I think there also it should be 15/04/2022 as the rest back orders can be fulfilled easily by 12,500 qty that is coming on 5th april.

 

 

@learner03 OK, the issue was the sort order of the purchase orders coming in. So, needed more complex DAX to convert the rows to a sorted string and then back to a table. Such a pain but the only way I know in DAX to guarantee ordering. So, the same while loop, just added code for the conversion to a sorted string and then back to a table. Updated PBIX attached.

 

Column = 
    VAR __DaysToFulfill = 10
    VAR __ItemCode = [Item Code]
    VAR __Date = [Date]
    VAR __QtyToFulfill = SUMX(FILTER('BackOrders',[Item Code] = __ItemCode && [Date] <= __Date),[Backorder Qty])
    VAR __SortedString = CONCATENATEX(FILTER(ALL('OpenPurchaseOrders'),[Item Code] = __ItemCode), [ETA W/H] & ":" & [Quantity], "|", [ETA W/H])
    VAR __Table = 
            ADDCOLUMNS(
                ADDCOLUMNS(
                    GENERATESERIES(1, PATHLENGTH(__SortedString),1),
                    "__row",PATHITEM(__SortedString,[Value])
                ),
                "__date",
                        VAR __Colon = FIND(":", [__row],)
                    RETURN
                        DATEVALUE(LEFT([__row],__Colon -1)),
                "__qty",
                        VAR __Colon = FIND(":", [__row],)
                        VAR __Len = LEN([__row])
                    RETURN
                        VALUE(RIGHT([__row], __Len - __Colon ))
            )
    VAR __Table1 = 
        ADDCOLUMNS(
            ADDCOLUMNS(__Table,"__tqty",SUMX(FILTER(__Table,[__date] <= EARLIER([__date])),[__qty])),
            "__LoopCounter",[__tqty] - __QtyToFulfill
        )
    VAR __TargetDate = MINX(FILTER(__Table1, [__LoopCounter] >= 0),[__date])
    VAR __FulfillmentDate = IF(__TargetDate = BLANK(),BLANK(),__TargetDate+__DaysToFulfill) 
RETURN
    __FulfillmentDate

 

 

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

I used your formula in the attached link but I am getting this below error-

https://drive.google.com/file/d/1iLS6xW1GyQUB0SFk7QR6413YwKYcEAgl/view?usp=sharing

 

akapoor03_0-1643843441262.png

What does this mean?

@learner03 Hmm. Very odd. I downloaded the file and do not get that error in the Column. That said, I did see that same exact error with a specific model setup and was thinking of posting an issue to the Issues forum which I think I will do now. I will post a link to the issue here once I open it. In the mean time, I have attached a version of the PBIX file that includes FIFO, LIFO, Optimized for Most Orders and Optimized for Most Quantity columns and measures.

Greg_Deckler_1-1643847037888.png

 

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thanks @Greg_Deckler 

Is it possible for you to attach the file that I shared in the link in which you applied the same formula ad didn't get the error? I would like to see that if I download it at my end, then am I getting the same error or not.

@learner03 Sure, here is the link to the issue: GENERATESERIES Bug? - Microsoft Power BI Community

 

And attached the PBIX that I downloaded.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler The file that you sent does has the old formula for the Column. It does not contain the new GENERATE series formula that you newly created. I need the fie in which you used the new formula at your end and didn't get any error as mine.Thanks

@learner03 OK, I simplified the equation and was able to eliminate the GENERATESERIES. Not sure why I didn't do it this way the first time. Try this one:

FIFO 2 = 
    VAR __DaysToFulfill = 10
    VAR __ItemCode = [Item Code]
    VAR __Date = [Date]
    VAR __QtyToFulfill = SUMX(FILTER('BackOrders',[Item Code] = __ItemCode && [Date] <= __Date),[Backorder Qty])
    VAR __Table = FILTER('OpenPurchaseOrders',[Item Code] = __ItemCode)
    VAR __Table1 = 
        ADDCOLUMNS(
            ADDCOLUMNS(__Table,"__tqty",SUMX(FILTER(__Table,[ETA W/H] <= EARLIER([ETA W/H])),[Quantity])),
            "__LoopCounter",[__tqty] - __QtyToFulfill
        )
    VAR __TargetDate = MINX(FILTER(__Table1, [__LoopCounter] >= 0),[ETA W/H])
    VAR __FulfillmentDate = IF(__TargetDate = BLANK(),BLANK(),__TargetDate+__DaysToFulfill) 
RETURN
    __FulfillmentDate

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Thanks Greg. I tried this one and checked couple of items, it works great with them as with desired result. I will check the same with the new updated file as this data was a week old. I will let you know if any issue occurs. I am acception this as a solution.Thanks again.

@learner03 Great to hear. If you need them, I revised the FIFO, LIFO and optimized columns and measures into FIFO 2, LIFO 2, etc. so you have 4 different ways of fulfilling backlog as both columns and measures without having to use GENERATESERIES. Attached PBIX.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler an extention to the report, how can I get the column next to the the new estimated delivery date where it can tell which associated Document number is used for the fulfilment of quantiy.

example-

In Backorder Table- the first few row are fulfilled by the first line of Open Puchase table. So, the associated Document number will be 229160 all the way through where 11/02/2022 and 230426 where 15/04 is in esti delivery column.

akapoor03_0-1643946770813.png

In Open Purchase table-

akapoor03_1-1643947138968.png

 

 

 

@learner03 Two ways based on the latest code from email. This version returns the last purchase order used to fulfill the backorder:

Purchase Orders Used = 
    VAR __DaysToFulfill = 10
    VAR __ItemCode = [Item Code]
    VAR __Simba = [Simba Ref#]
    VAR __Date = [Date]
    VAR __QtyToFulfill = 
        SUMX(
            FILTER(
                'Backorders',
                [Item Code] = __ItemCode && 
                VALUE( TRUNC([Date]) & "." & RIGHT([Simba Ref#],LEN([Simba Ref#])-2)) <= VALUE( TRUNC(__Date) & "." & RIGHT(__Simba,LEN(__Simba)-2))
            ),
            [Backorder Qty]
        )
    VAR __Table = FILTER('On Purchase',[Item Code] = __ItemCode)
    VAR __Table1 = 
        ADDCOLUMNS(
            ADDCOLUMNS(__Table,"__tqty",SUMX(FILTER(__Table,[ETA W/H] <= EARLIER([ETA W/H])),[Qty Balance])),
            "__LoopCounter",[__tqty] - __QtyToFulfill
        )
    VAR __TargetDate = MINX(FILTER(__Table1, [__LoopCounter] >= 0),[ETA W/H])
    VAR __FulfillmentDate = IF(__TargetDate = BLANK(),BLANK(),__TargetDate+__DaysToFulfill) 
RETURN
    MAXX(FILTER(__Table1,[ETA W/H] = __TargetDate),[Document Number])

Here is one that preserves history so to speak:

Purchase Orders Used 2 = 
    VAR __DaysToFulfill = 10
    VAR __ItemCode = [Item Code]
    VAR __Simba = [Simba Ref#]
    VAR __Date = [Date]
    VAR __QtyToFulfill = 
        SUMX(
            FILTER(
                'Backorders',
                [Item Code] = __ItemCode && 
                VALUE( TRUNC([Date]) & "." & RIGHT([Simba Ref#],LEN([Simba Ref#])-2)) <= VALUE( TRUNC(__Date) & "." & RIGHT(__Simba,LEN(__Simba)-2))
            ),
            [Backorder Qty]
        )
    VAR __Table = FILTER('On Purchase',[Item Code] = __ItemCode)
    VAR __Table1 = 
        ADDCOLUMNS(
            ADDCOLUMNS(__Table,"__tqty",SUMX(FILTER(__Table,[ETA W/H] <= EARLIER([ETA W/H])),[Qty Balance])),
            "__LoopCounter",[__tqty] - __QtyToFulfill
        )
    VAR __TargetDate = MINX(FILTER(__Table1, [__LoopCounter] >= 0),[ETA W/H])
    VAR __FulfillmentDate = IF(__TargetDate = BLANK(),BLANK(),__TargetDate+__DaysToFulfill) 
RETURN
    CONCATENATEX(FILTER(__Table1,[ETA W/H] <= __TargetDate),[Document Number],", ")

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler That's Brilliant !! Thanks again

@learner03 Oh, sorry, I just opened your file and looked at Column and it did not have an error. Anyway, oddly enough, if I add a column with the new formula in it, I also get the error. The disturbing part is that your model and my model are identical other than table names, 2 disconnected tables. That makes it even more strange. There is something wrong with GENERATESERIES. See the Issue posting for more details but this just makes it completely weird. 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

I will keep seeing the post if someone respond to that. Meanwhile, in case if you find a solution at your end, Please do let me know. This is a very urgent project.

 

Thanks a lot for your efforts.

@Greg_Deckler https://drive.google.com/file/d/1iLS6xW1GyQUB0SFk7QR6413YwKYcEAgl/view?usp=sharing 

I used your formula in the attached pbix and I saw that there are few gaps in the new column that calculated delivery dates.

For example if I see Item Code "9013" in both the tables. The place where it is calculating till estimated date 15/2 is working correctly, after this it is going blank.

akapoor03_0-1643755506819.png

and in Open Purchase order table, I can see that there is more stock coming and it can fulfil the back order amount-

akapoor03_1-1643755586738.png

 

 

@learner03 The blanks come in when there is not enough product coming in from purchase orders to fulfill the request. Therefore, no estimated delivery date. I will check the calculations to see where things are coming from.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors