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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Tan_LC
Helper II
Helper II

DAX Formula to calculate the Order Date in Inventory Management

Hi,

 

In below table, there are 2 Material No. (A060 & H846F) with the date range from 16/11/2022 till 31/01/2023.

In order to get the "Order Date (Desired column)", below criterias shall be fulfilled:

 

1. The Date with the earliest Stock Day(s) < 60 days shall be captured.

2. Any BLANK() cell in Stock Day(s) column or last day of the month shall be ignored/excluded.

 

Please use DAX Formula instead of Query Editor.

 

DateMaterial NoStock Day(s)Order Date
(Desired column)
16/11/2022A06046.5 
17/11/2022A06046.5 
18/11/2022A060  
19/11/2022A060  
20/11/2022A06039.8 
21/11/2022A06053.2 
22/11/2022A06048.8 
23/11/2022A06049.4 
24/11/2022A06045.3 
25/11/2022A06069.7 
26/11/2022A06079.4 
27/11/2022A06053.2 
28/11/2022A06081.5 
29/11/2022A06082.8 
30/11/2022A060127.8 
01/12/2022A06056.801/12/2022
02/12/2022A06055.801/12/2022
03/12/2022A06054.801/12/2022
04/12/2022A06053.801/12/2022
05/12/2022A06052.801/12/2022
06/12/2022A06051.801/12/2022
07/12/2022A06050.801/12/2022
08/12/2022A06049.801/12/2022
09/12/2022A06048.801/12/2022
10/12/2022A06047.801/12/2022
11/12/2022A06046.801/12/2022
12/12/2022A06045.801/12/2022
13/12/2022A06044.801/12/2022
14/12/2022A06043.801/12/2022
15/12/2022A06042.801/12/2022
16/12/2022A06041.801/12/2022
17/12/2022A06040.801/12/2022
18/12/2022A06039.801/12/2022
19/12/2022A06038.801/12/2022
20/12/2022A06037.801/12/2022
21/12/2022A06036.801/12/2022
22/12/2022A06035.801/12/2022
23/12/2022A06034.801/12/2022
24/12/2022A06033.801/12/2022
25/12/2022A06032.801/12/2022
26/12/2022A06031.801/12/2022
27/12/2022A06030.801/12/2022
28/12/2022A06029.801/12/2022
29/12/2022A06028.801/12/2022
30/12/2022A06028.801/12/2022
31/12/2022A060  
01/01/2023A06029.701/12/2022
02/01/2023A06028.701/12/2022
03/01/2023A06027.701/12/2022
04/01/2023A06026.701/12/2022
05/01/2023A06025.701/12/2022
06/01/2023A06024.701/12/2022
07/01/2023A06023.701/12/2022
08/01/2023A06022.701/12/2022
09/01/2023A06021.701/12/2022
10/01/2023A06020.701/12/2022
11/01/2023A06019.701/12/2022
12/01/2023A06018.701/12/2022
13/01/2023A06017.701/12/2022
14/01/2023A06016.701/12/2022
15/01/2023A06015.701/12/2022
16/01/2023A06014.701/12/2022
17/01/2023A06013.701/12/2022
18/01/2023A06012.701/12/2022
19/01/2023A06011.701/12/2022
20/01/2023A06010.701/12/2022
21/01/2023A0609.701/12/2022
22/01/2023A0608.701/12/2022
23/01/2023A0607.701/12/2022
24/01/2023A0606.701/12/2022
25/01/2023A0605.701/12/2022
26/01/2023A0604.701/12/2022
27/01/2023A0603.701/12/2022
28/01/2023A0602.701/12/2022
29/01/2023A0601.701/12/2022
30/01/2023A0600.701/12/2022
31/01/2023A060-0.3 
01/12/2022H846F1004.7 
02/12/2022H846F1003.7 
03/12/2022H846F1002.7 
04/12/2022H846F1001.7 
05/12/2022H846F1000.7 
06/12/2022H846F999.7 
07/12/2022H846F998.7 
08/12/2022H846F997.7 
09/12/2022H846F996.7 
10/12/2022H846F995.7 
11/12/2022H846F994.7 
12/12/2022H846F993.7 
13/12/2022H846F992.7 
14/12/2022H846F991.7 
15/12/2022H846F990.7 
16/12/2022H846F989.7 
17/12/2022H846F988.7 
18/12/2022H846F987.7 
19/12/2022H846F986.7 
20/12/2022H846F985.7 
21/12/2022H846F984.7 
22/12/2022H846F983.7 
23/12/2022H846F982.7 
24/12/2022H846F981.7 
25/12/2022H846F980.7 
26/12/2022H846F979.7 
27/12/2022H846F978.7 
28/12/2022H846F977.7 
29/12/2022H846F976.7 
30/12/2022H846F976.7 
31/12/2022H846F  
01/01/2023H846F44.401/01/2023
02/01/2023H846F43.401/01/2023
03/01/2023H846F42.401/01/2023
04/01/2023H846F41.401/01/2023
05/01/2023H846F40.401/01/2023
06/01/2023H846F39.401/01/2023
07/01/2023H846F38.401/01/2023
08/01/2023H846F37.401/01/2023
09/01/2023H846F36.401/01/2023
10/01/2023H846F35.401/01/2023
11/01/2023H846F34.401/01/2023
12/01/2023H846F33.401/01/2023
13/01/2023H846F32.401/01/2023
14/01/2023H846F31.401/01/2023
15/01/2023H846F30.401/01/2023
16/01/2023H846F29.401/01/2023
17/01/2023H846F28.401/01/2023
18/01/2023H846F27.401/01/2023
19/01/2023H846F26.401/01/2023
20/01/2023H846F25.401/01/2023
21/01/2023H846F24.401/01/2023
22/01/2023H846F23.401/01/2023
23/01/2023H846F22.401/01/2023
24/01/2023H846F21.401/01/2023
25/01/2023H846F20.401/01/2023
26/01/2023H846F19.401/01/2023
27/01/2023H846F18.401/01/2023
28/01/2023H846F17.401/01/2023
29/01/2023H846F16.401/01/2023
30/01/2023H846F15.401/01/2023
31/01/2023H846F14.3 

 

Thank you.

 

Regards,

Lee Cheng

1 ACCEPTED SOLUTION

Hi @Tan_LC ,

 

You can try this method:

New two columns:

Max =
CALCULATE (
    MAX ( 'Table'[Date] ),
    FILTER (
        'Table',
        'Table'[Material No] = EARLIER ( 'Table'[Material No] )
            && 'Table'[Stock Day(s) (without Delivery)] >= 60
            && 'Table'[Date] <> EOMONTH ( 'Table'[Date], 0 )
    )
)

 

Result =
IF (
    'Table'[Stock Day(s) (without Delivery)] >= 60
        || 'Table'[Stock Day(s) (without Delivery)] = BLANK ()
        || 'Table'[Date] = EOMONTH ( 'Table'[Date], 0 ),
    BLANK (),
    IF ( 'Table'[Date] < 'Table'[Max], BLANK (), 'Table'[Max] + 2 )
)

 The result is:

vyinliwmsft_0-1669712287194.png

Hope this helps you.

Here is my PBIX file.

 

Best Regards,

Community Support Team _Yinliw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yinliw-msft
Community Support
Community Support

Hi @Tan_LC , 

 

You can try this method:

New columns:

 

 

Month = MONTH('Table'[Date])
Max = CALCULATE ( MAX ( 'Table'[Stock Day(s)] ), FILTER ( 'Table', 'Table'[Month] = EARLIER ( 'Table'[Month] ) && 'Table'[Material No] = EARLIER ( 'Table'[Material No] ) ) )

 

 

OrderDate(Result) =
IF (
'Table'[Max] > 60
|| 'Table'[Date] = EOMONTH ( 'Table'[Date], 0 ),
BLANK (),
CALCULATE (
MIN ( 'Table'[Date] ),
FILTER (
'Table',
'Table'[Material No] = EARLIER ( 'Table'[Material No] )
&& 'Table'[Max] <= 60
)
)
The result is:
vyinliwmsft_1-1669626099415.png

 

 
 vyinliwmsft_0-1669626065671.png

 

 
 

Hope this helps you.

Here is my PBIX file.

 

Best Regards,

Community Support Team _Yinliw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

Hi all, thanks for the reply.

 

I've tried on the DAX formula given, however when longer duration data is load, the Order Date doesn't seem to be accurate. Thus, I would like to add on additional criteria as below:

 

Example: 

Material A013, Order Date should always captured the latest < 60 days Date which is 01/11/2022 instead of  21/09/2022, it was due to on 01/10/2022 onwards, there were few Stock Day(s) above 60 days. 

 

Hope my explanation is clear and thanks for the help.

 

DateMaterial NoStock Day(s) (without Delivery)To Order Date
(Desired column)
21/09/2022A01334 
22/09/2022A01332.8 
23/09/2022A01338.3 
24/09/2022A01337.3 
25/09/2022A01336.6 
26/09/2022A01334.9 
27/09/2022A01334.9 
28/09/2022A01341.9 
29/09/2022A01341.6 
30/09/2022A01350.1 
01/10/2022A013154.1 
02/10/2022A013142.4 
03/10/2022A013138.9 
04/10/2022A013150.3 
05/10/2022A013150.6 
06/10/2022A013150.9 
07/10/2022A013148.5 
08/10/2022A013147.4 
09/10/2022A013154 
10/10/2022A013133.8 
11/10/2022A013132.7 
12/10/2022A013124.9 
13/10/2022A013125.6 
14/10/2022A013121.7 
15/10/2022A013118.3 
16/10/2022A013119.5 
17/10/2022A013131.3 
18/10/2022A013131.5 
19/10/2022A013133.6 
20/10/2022A013156.1 
21/10/2022A013164.4 
22/10/2022A013184.4 
23/10/2022A013  
24/10/2022A013  
25/10/2022A013  
26/10/2022A013189.1 
27/10/2022A013168.8 
28/10/2022A013157.8 
29/10/2022A013163 
30/10/2022A013182.7 
31/10/2022A013233.8 
01/11/2022A01344.101/11/2022
02/11/2022A01338.601/11/2022
03/11/2022A01341.301/11/2022
04/11/2022A013  
05/11/2022A013  
06/11/2022A013  
07/11/2022A01339.901/11/2022
08/11/2022A01334.501/11/2022
09/11/2022A01334.601/11/2022
10/11/2022A01333.601/11/2022
11/11/2022A01333.201/11/2022
12/11/2022A01332.501/11/2022
13/11/2022A01331.301/11/2022
14/11/2022A01329.301/11/2022
15/11/2022A01330.801/11/2022
16/11/2022A01330.101/11/2022
17/11/2022A01328.201/11/2022
18/11/2022A013  
19/11/2022A013  
20/11/2022A01323.401/11/2022
21/11/2022A01328.501/11/2022
22/11/2022A01344.701/11/2022
23/11/2022A0134501/11/2022
24/11/2022A01346.101/11/2022
25/11/2022A0134501/11/2022
26/11/2022A01351.201/11/2022
27/11/2022A01333.501/11/2022
28/11/2022A01349.301/11/2022
29/11/2022A01349.801/11/2022
30/11/2022A01375.1 
01/12/2022A01332.901/11/2022
02/12/2022A01331.901/11/2022
03/12/2022A01330.901/11/2022
04/12/2022A01329.901/11/2022
05/12/2022A01328.901/11/2022
06/12/2022A01327.901/11/2022
07/12/2022A01326.901/11/2022
08/12/2022A01325.901/11/2022
09/12/2022A01324.901/11/2022
10/12/2022A01323.901/11/2022
11/12/2022A01322.901/11/2022
12/12/2022A01321.901/11/2022
13/12/2022A01320.901/11/2022
14/12/2022A01319.901/11/2022
15/12/2022A01318.901/11/2022
16/12/2022A01317.901/11/2022
17/12/2022A01316.901/11/2022
18/12/2022A01315.901/11/2022
19/12/2022A01314.901/11/2022
20/12/2022A01313.901/11/2022
21/12/2022A01312.901/11/2022
22/12/2022A01311.901/11/2022
23/12/2022A01310.901/11/2022
24/12/2022A0139.901/11/2022
25/12/2022A0138.901/11/2022
26/12/2022A0137.901/11/2022
27/12/2022A0136.901/11/2022
28/12/2022A0135.901/11/2022
29/12/2022A0134.901/11/2022
30/12/2022A0134.901/11/2022
31/12/2022A013  
01/01/2023A0133.301/11/2022
02/01/2023A0132.301/11/2022
03/01/2023A0131.301/11/2022
04/01/2023A0130.301/11/2022
05/01/2023A013-0.701/11/2022
21/09/2022A06038.1 
22/09/2022A06037 
23/09/2022A06060.7 
24/09/2022A06060 
25/09/2022A06059.6 
26/09/2022A06056 
27/09/2022A06056.2 
28/09/2022A06055 
29/09/2022A06055 
30/09/2022A06067.5 
01/10/2022A060195.1 
02/10/2022A060179 
03/10/2022A060174.6 
04/10/2022A060151.9 
05/10/2022A060152.5 
06/10/2022A060155.9 
07/10/2022A060152.7 
08/10/2022A060151.3 
09/10/2022A060159.3 
10/10/2022A060155.7 
11/10/2022A060155.4 
12/10/2022A060148.6 
13/10/2022A060151.1 
14/10/2022A060133.1 
15/10/2022A060129.7 
16/10/2022A060131.8 
17/10/2022A060131.1 
18/10/2022A060131.5 
19/10/2022A060132.8 
20/10/2022A060131.5 
21/10/2022A060124.1 
22/10/2022A060139.7 
23/10/2022A060  
24/10/2022A060  
25/10/2022A060  
26/10/2022A060142.9 
27/10/2022A060128.7 
28/10/2022A060120.7 
29/10/2022A060123.5 
30/10/2022A060137.8 
31/10/2022A060364.9 
01/11/2022A06070.7 
02/11/2022A06061.6 
03/11/2022A06067.4 
04/11/2022A060  
05/11/2022A060  
06/11/2022A060  
07/11/2022A06067.9 
08/11/2022A06055.8 
09/11/2022A06055.5 
10/11/2022A06056.6 
11/11/2022A06055.6 
12/11/2022A06054.9 
13/11/2022A06053.3 
14/11/2022A06045.5 
15/11/2022A06047.5 
16/11/2022A06046.5 
17/11/2022A06046.5 
18/11/2022A060  
19/11/2022A060  
20/11/2022A06039.8 
21/11/2022A06053.2 
22/11/2022A06048.8 
23/11/2022A06049.4 
24/11/2022A06045.3 
25/11/2022A06069.7 
26/11/2022A06079.4 
27/11/2022A06053.2 
28/11/2022A06085 
29/11/2022A06086.5 
30/11/2022A060133.6 
01/12/2022A06059.401/12/2022
02/12/2022A06058.401/12/2022
03/12/2022A06057.401/12/2022
04/12/2022A06056.401/12/2022
05/12/2022A06055.401/12/2022
06/12/2022A06054.401/12/2022
07/12/2022A06053.401/12/2022
08/12/2022A06052.401/12/2022
09/12/2022A06051.401/12/2022
10/12/2022A06050.401/12/2022
11/12/2022A06049.401/12/2022
12/12/2022A06048.401/12/2022
13/12/2022A06047.401/12/2022
14/12/2022A06046.401/12/2022
15/12/2022A06045.401/12/2022
16/12/2022A06044.401/12/2022
17/12/2022A06043.401/12/2022
18/12/2022A06042.401/12/2022
19/12/2022A06041.401/12/2022
20/12/2022A06040.401/12/2022
21/12/2022A06039.401/12/2022
22/12/2022A06038.401/12/2022
23/12/2022A06037.401/12/2022
24/12/2022A06036.401/12/2022
25/12/2022A06035.401/12/2022
26/12/2022A06034.401/12/2022
27/12/2022A06033.401/12/2022
28/12/2022A06032.401/12/2022
29/12/2022A06031.401/12/2022
30/12/2022A06031.401/12/2022
31/12/2022A060  
01/01/2023A06032.501/12/2022
02/01/2023A06031.501/12/2022
03/01/2023A06030.501/12/2022
04/01/2023A06029.501/12/2022
05/01/2023A06028.501/12/2022

 

Regards,

Lee Cheng

Hi @Tan_LC ,

 

You can try this method:

New two columns:

Max =
CALCULATE (
    MAX ( 'Table'[Date] ),
    FILTER (
        'Table',
        'Table'[Material No] = EARLIER ( 'Table'[Material No] )
            && 'Table'[Stock Day(s) (without Delivery)] >= 60
            && 'Table'[Date] <> EOMONTH ( 'Table'[Date], 0 )
    )
)

 

Result =
IF (
    'Table'[Stock Day(s) (without Delivery)] >= 60
        || 'Table'[Stock Day(s) (without Delivery)] = BLANK ()
        || 'Table'[Date] = EOMONTH ( 'Table'[Date], 0 ),
    BLANK (),
    IF ( 'Table'[Date] < 'Table'[Max], BLANK (), 'Table'[Max] + 2 )
)

 The result is:

vyinliwmsft_0-1669712287194.png

Hope this helps you.

Here is my PBIX file.

 

Best Regards,

Community Support Team _Yinliw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

FreemanZ
Super User
Super User

hi @Tan_LC 

try to add a new column with the code below:

 

OrderDate =
VAR CurrentMaterial = TableName[MaterialNo]
VAR table1 =
FILTER(
    TableName,
    TableName[StockDays]<=60
        && TableName[MaterialNo] = CurrentMaterial
)
VAR value1 =
MAXX(table1, TableName[StockDays])
VAR table2 =
FILTER(
    table1,
    TableName[StockDays] = value1
)
VAR table3 =
SELECTCOLUMNS(table2, "Date", TableName[Date])
VAR value2 =
IF(
    COUNTROWS(table3)=1,
    table3
)
RETURN
IF(    
TableName[StockDays]<>BLANK()
    && TableName[Date] >= value2
    && VAR value3 = ENDOFMONTH(TableName[Date])
            RETURN TableName[Date]<>value3,
value2
)
 
i tried and it worked like this:
FreemanZ_0-1669605417725.png

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.