Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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],
'Processed Data'[Date of failure],
'Processed Data'[Date of repair])
)
WorkingDay = SWITCH(CalendarTable[WeekNo],1,0,7,0,1)
But i realized that i forgot to add the holidays in the equation of the working day, on top of that, i have difficulty because my data is across different countries that does not share the same holidays.
I shared the data below.
https://drive.google.com/open?id=1RmBqHxvPOYZ-wTEplvaOlln_ajjnnKP8
Thanks in advance for the help.
I have a column for the country in each row so it can be used to filter the TAT computation based on the country holiday list, I guess.
I have been at it for hours and can't seem to figure out how to do it. Any help will be appreciated.
Solved! Go to Solution.
Hi@Anonymous
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:
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] ) )
Proud to be a Super User!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
97 | |
77 | |
63 | |
55 |
User | Count |
---|---|
143 | |
109 | |
89 | |
84 | |
66 |