Forum Discussion
Anonymous
8 years agoNot applicable
NETWORKDAYS with multiple country holidays
Hi, I am computing the difference between two working dates to know the lenght of days used, the formula is below; TAT = CALCULATE(SUM(CalendarTable[WorkingDay]), DATESBETWEEN(CalendarTable[Date...
- 8 years ago
HiAnonymous
For this use case, you need to calculate first the number of weekdays within your specified date range then deduct the number of weekdays that are holidays. Here's what I've come up with:
NETWORKDAYS W/ HOLIDAYS = VAR HOLIDAYS_ = CALCULATE ( SUM ( Holidays[Is Weekday?] ), DATESBETWEEN ( Holidays[Date], 'Processed Data'[Date of failure], 'Processed Data'[Date of repair] ), Holidays[Country] = EARLIER ( 'Processed Data'[Country] ) ) VAR REGuLAR_NETWORKKDAYS_ = CALCULATE ( SUM ( Dates[Is Weekday?] ), DATESBETWEEN ( Dates[Date], 'Processed Data'[Date of failure], 'Processed Data'[Date of repair] ) ) RETURN REGULAR_NETWORKKDAYS_ - HOLIDAYS_Please note that:
- HOLIDAYS and Dates tables are disconnected tables. They don't have any relationships with your fact table.
- DATESBETWEEN() behaves similarly with NETWORKDAYS in Excel. It aggregates the values within a specified date range and not the difference between the end and start dates. That being said, you might want to deduct 1 from the measure above and return 0 if after deducting 1 the result is negative.
Also, you can create a date calendar in DAX or M without pulling in data from an externa source. Here are sample codes:
M -
let Source = List.Dates(#date(2018, 1, 1), Number.From(DateTime.Date(DateTime.LocalNow()) - #date(2018,1,1)) +1, #duration(1,0,0,0)), #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), {"Date"}, null, ExtraValues.Error), #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Date", type date}}), #"Inserted Day Name" = Table.AddColumn(#"Changed Type", "Day Name", each Date.DayOfWeekName([Date]), type text), #"Added Custom" = Table.AddColumn(#"Inserted Day Name", "Is Weekday?", each if [Day Name]="Saturday" or [Day Name]="Sunday" then 0 else 1, Int64.Type) in #"Added Custom"DAX
CALENDAR Table = CALENDAR ( MIN ( 'Processed Data'[Date of failure] ), MAX ( 'Processed Data'[Date of repair] ) )
danextian
6 years agoSuper User
Please post a sample data that is not screen caps and a sample table of your expected result.
Anonymous
6 years agoNot applicable
| Invoice Date | Posted Date | Payment Date | Date Due | Type of supplier | Invoice Received on |
| 13-06-2019 | 31-07-2019 | 06-12-2019 | 13-07-2019 | 3rd Party | 12-07-2019 |
| 15-04-2019 | 12-08-2019 | 06-12-2019 | 15-05-2019 | 3rd Party | 08-08-2019 |
| 22-10-2019 | 30-10-2019 | 13-12-2019 | 21-11-2019 | 3rd Party | 29-10-2019 |
| 24-10-2019 | 30-10-2019 | 13-12-2019 | 23-11-2019 | 3rd Party | 29-10-2019 |
| 31-10-2019 | 07-11-2019 | 16-12-2019 | 30-11-2019 | 3rd Party | 31-10-2019 |
| 29-10-2019 | 12-11-2019 | 13-12-2019 | 28-11-2019 | 3rd Party | 06-11-2019 |
| 31-10-2019 | 28-11-2019 | 06-12-2019 | 30-11-2019 | 3rd Party | 08-11-2019 |
| 04-11-2019 | 12-11-2019 | 04-12-2019 | 04-12-2019 | 3rd Party | 11-11-2019 |
| 05-11-2019 | 15-11-2019 | 06-12-2019 | 05-12-2019 | 3rd Party | 11-11-2019 |
| 31-10-2019 | 28-11-2019 | 06-12-2019 | 30-11-2019 | 3rd Party | 12-11-2019 |
| 31-10-2019 | 18-11-2019 | 13-12-2019 | 30-11-2019 | 3rd Party | 12-11-2019 |
| 31-10-2019 | 18-11-2019 | 13-12-2019 | 30-11-2019 | 3rd Party | 12-11-2019 |
| 01-11-2019 | 18-11-2019 | 30-12-2019 | 01-12-2019 | 3rd Party | 12-11-2019 |
| 31-10-2019 | 18-11-2019 | 13-12-2019 | 30-11-2019 | 3rd Party | 13-11-2019 |
| 08-11-2019 | 18-11-2019 | 30-12-2019 | 08-12-2019 | 3rd Party | 14-11-2019 |
| 28-05-2019 | 28-11-2019 | 06-12-2019 | 27-06-2019 | 3rd Party | 15-11-2019 |
| 12-11-2019 | 18-11-2019 | 30-12-2019 | 12-12-2019 | 3rd Party | 15-11-2019 |
| 31-10-2019 | 20-11-2019 | 13-12-2019 | 30-11-2019 | 3rd Party | 18-11-2019 |
| 01-10-2019 | 20-11-2019 | 13-12-2019 | 31-10-2019 | 3rd Party | 19-11-2019 |
| 04-10-2019 | 20-11-2019 | 13-12-2019 | 03-11-2019 | 3rd Party | 19-11-2019 |
| 05-11-2019 | 27-11-2019 | 06-12-2019 | 05-12-2019 | 3rd Party | 21-11-2019 |
| 06-11-2019 | 27-11-2019 | 06-12-2019 | 06-12-2019 | 3rd Party | 21-11-2019 |
| 09-11-2019 | 27-11-2019 | 06-12-2019 | 09-12-2019 | 3rd Party | 21-11-2019 |
| 14-11-2019 | 27-11-2019 | 06-12-2019 | 14-12-2019 | 3rd Party | 21-11-2019 |
| 15-10-2019 | 27-11-2019 | 12-12-2019 | 14-11-2019 | 3rd Party | 21-11-2019 |
| 01-12-2019 | 01-12-2019 | 13-12-2019 | 31-12-2019 | 3rd Party | 22-11-2019 |
| 01-12-2019 | 01-12-2019 | 13-12-2019 | 31-12-2019 | 3rd Party | 22-11-2019 |
The Expected result in Excel:
| Invoice Date to Receipt Date (Calender Days ) | Invoice Date to Payment Date (Calender Days ) | Receipt Date to Posting Date ( Working Days ) | Receipt Date to Payment Date (Working Days) | Posting to Payment Date |
| -3 | -31306 | 2 | -31305 | -31,307 |
| 5 | -31300 | 2 | -31305 | -31,307 |
| 20 | -31284 | 2 | -31305 | -31,307 |
| 3 | -31298 | 4 | -31301 | -31,305 |
| 3 | -31298 | 1 | -31301 | -31,302 |
| 1 | -31298 | 2 | -31299 | -31,301 |
| 10 | -31289 | 2 | -31299 | -31,301 |
| -9 | -31299 | 8 | -31292 | -31,300 |
| 13 | -31284 | 1 | -31298 | -31,299 |
| 2 | -31293 | 3 | -31295 | -31,298 |
| 2 | -31293 | 3 | -31295 | -31,298 |
| 4 | -31291 | 3 | -31295 | -31,298 |
| 2 | -31289 | 2 | -31292 | -31,294 |
| 2 | -31285 | 3 | -31287 | -31,290 |
| 4 | 24 | 265 | 20 | -247 |
| 0 | 1 | 1 | 1 | - |
| 18 | 19 | 1 | 1 | - |
| 125 | 126 | 1 | 1 | - |
| 168 | 169 | 1 | 1 | - |
| 8 | 10 | 2 | 2 | - |
| 12 | 14 | 2 | 2 | - |
| 57 | 59 | 2 | 2 | - |
| 0 | 3 | 3 | 3 | - |
| 3 | 6 | 3 | 3 | - |
| 4 | 7 | 3 | 3 | - |
| 10 | 13 | 3 | 3 | - |
| 15 | 18 | 2 | 3 | 1 |
| 18 | 21 | 2 | 3 | 1 |
| 5 | 8 | 1 | 3 | 2 |
| 10 | 14 | 2 | 4 | 2 |
| 2 | 9 | 2 | 7 | 5 |
| 2 | 14 | 6 | 12 | 6 |
| 122 | 138 | 10 | 16 | 6 |
| 8 | 27 | 13 | 19 | 6 |
| 6 | 27 | 15 | 21 | 6 |
| 0 | 9 | 2 | 9 | 7 |
| 22 | 32 | 3 | 10 | 7 |