Forum Discussion
Display the max date before a specific deadline for 2 date tables
Hi,
I would like to know when shall we place a purchase order before the deadline in case suppliers are on holidays.
Ex. if the Expected delivery date is 31.12.2020 (could be any date) then the start of the procurement process shall begin 50 days prior, on 11.11.2020. (that’s done) But we need to make sure we consider all the supplier vacation between Expected delivery date and procurement process start date (only start date).
So lets say between 31.12.2020 and 11.11.2020 there are suppliers who have together around 14 days of holiday. Then from date 11.11.2020 we should calculate / deduct these 14 days to obtain 28.10.2020 new order date.
Ex.
Table 1:
Column 1 - Expected date of del. Column B Expected day of del. (Procurement) -50 days
DAX date range Column 1 – 50 days
01.01.2020
to
31.12.2040
Table 2: Supplier holidays example
Column 1 Column 2 - Start Holiday Column 3 - End Holiday
Supplier A Holiday 1 03.04.2020 07.03.2020
Supplier A Holiday 2 11.05.2020 18.05.2020
Supplier B Holiday 1 06.04.2020 08.04.2020
Supplier B Holiday 2 18.09.2020 25.09.2020
Supplier B Holiday 3 07.11.2020 15.11.2020
and so on
Both tables could be related via date only.
Many thanks
Hi, Anonymous
Based on your description, I created data to reproduce your scenario.
Table1(a calculated table):
Table 1 = CALENDAR(DATE(2020,1,1),DATE(2020,12,31))Supplier holiday:
Then you may create a calculated column and three measures as follows.
calculated column: Supplier = LEFT('Supplier holiday'[Supplier Holiday],10) measures: Holidays = var _currentdel = SELECTEDVALUE('Table 1'[Expected date of del.]) var _currentdel50 = SELECTEDVALUE('Table 1'[Procurement]) var _startdate = MAX('Supplier holiday'[Start Holiday]) var _enddate = MAX('Supplier holiday'[End Holiday]) return SWITCH( TRUE(), OR(_startdate>_currentdel,_enddate<_currentdel50),0, AND(_startdate<_currentdel50,_enddate>_currentdel50),DATEDIFF(_currentdel50,_enddate,DAY), AND(_startdate>=_currentdel50,_enddate<=_currentdel),DATEDIFF(_startdate,_enddate,DAY), AND(_startdate<_currentdel,_enddate>_currentdel),DATEDIFF(_startdate,_currentdel,DAY), BLANK() ) TotalsDays = var _currentsupplier = MAX('Supplier holiday'[Supplier]) return SUMX( FILTER( ALLSELECTED('Supplier holiday'), 'Supplier holiday'[Supplier] = _currentsupplier ), [Holidays] )+50 Max Date = SELECTEDVALUE('Table 1'[Expected date of del.])-[TotalsDays]Finally, you may use 'Expected date of del.' from Table1 as the slicer and a table visual to display the result.
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- v-alq-msft
Community Support
Hi, Anonymous
Based on your description, I created data to reproduce your scenario.
Table1(a calculated table):
Table 1 = CALENDAR(DATE(2020,1,1),DATE(2020,12,31))Supplier holiday:
Then you may create a calculated column and three measures as follows.
calculated column: Supplier = LEFT('Supplier holiday'[Supplier Holiday],10) measures: Holidays = var _currentdel = SELECTEDVALUE('Table 1'[Expected date of del.]) var _currentdel50 = SELECTEDVALUE('Table 1'[Procurement]) var _startdate = MAX('Supplier holiday'[Start Holiday]) var _enddate = MAX('Supplier holiday'[End Holiday]) return SWITCH( TRUE(), OR(_startdate>_currentdel,_enddate<_currentdel50),0, AND(_startdate<_currentdel50,_enddate>_currentdel50),DATEDIFF(_currentdel50,_enddate,DAY), AND(_startdate>=_currentdel50,_enddate<=_currentdel),DATEDIFF(_startdate,_enddate,DAY), AND(_startdate<_currentdel,_enddate>_currentdel),DATEDIFF(_startdate,_currentdel,DAY), BLANK() ) TotalsDays = var _currentsupplier = MAX('Supplier holiday'[Supplier]) return SUMX( FILTER( ALLSELECTED('Supplier holiday'), 'Supplier holiday'[Supplier] = _currentsupplier ), [Holidays] )+50 Max Date = SELECTEDVALUE('Table 1'[Expected date of del.])-[TotalsDays]Finally, you may use 'Expected date of del.' from Table1 as the slicer and a table visual to display the result.
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- AnonymousNot applicable
Hi Allan,
We were confronted with an issue that could be seen in the attached picture.
**We changed the procurement date as 211 from Expected deliv. date instead of 50
Issue: The MAX Date does not display the earliest date we shall start the procurement process due to (I assume) incorrect count of the Holidays and Total days. We would think that it shall sum up the "Holidays" so (15+11+4+4+2) with the 211 days (50 previously) and based on this sum it shall be displayed like MAX Date as Expected deliv date - 211-15-11-4-4-2 giving us 18.02.2020
Appreciate your time & effort / let me know if more details are requried
Best regards