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 calculating the duration between 2 events.
We have an event start date and event end date.
Both fields are DATETIME.
I can calculate the duration between the two events and transform to total hours easily.
How can I remove weekends from the calculation?
Solved! Go to Solution.
Ended up using this.
Worked perfectly.
Datediff(HH, Event_Date_Start, Event_Date_end)
+ CASE WHEN Datepart(dw, Event_Date_Start) = 7 THEN 1 ELSE 0 END
- (Datediff(wk, Event_Date_Start, Event_Date_end) * 48 )
- CASE WHEN Datepart(dw, Event_Date_Start) = 1 THEN 1 ELSE 0 END +
- CASE WHEN Datepart(dw, Event_Date_end) = 1 THEN 1 ELSE 0
end
You can change the 48 to 2 if you want this to work in days.
Hi @Anonymous,
Why dont you use a time dimension table in which you can have 'IsWeekDay' flag.
Create relationship between this dimension table with your other table based on date.
And then use this flag in your duration calculation.
I have just suggested an approach to you, you can try it.
Thanks !!
Thanks! Do you have a link to a thread where someone has done this?
I'm quite new to Power BI/BI in general.
Hi @Anonymous,
Sorry, not aware of any link.
Just Google DateDimension table and download the SQL script.
In case if that flag is not available then you can create using simple SQL DateTime functions.
Thanks !!
After a bit of reading it seems that it would exclude start and end times on the weekend as well.
Just say an event starts on a Thrusday at 14:00 and ends on Monday at 14:00.
I want my duration to be 48 hours and not 96 Hours (48 hours of weekend to be excluded).
Or if an item starts on a Saturday or Sunday the timing must only commence on Monday at 00:00.
Anyone done something like this in Power BI or sql?
Ended up using this.
Worked perfectly.
Datediff(HH, Event_Date_Start, Event_Date_end)
+ CASE WHEN Datepart(dw, Event_Date_Start) = 7 THEN 1 ELSE 0 END
- (Datediff(wk, Event_Date_Start, Event_Date_end) * 48 )
- CASE WHEN Datepart(dw, Event_Date_Start) = 1 THEN 1 ELSE 0 END +
- CASE WHEN Datepart(dw, Event_Date_end) = 1 THEN 1 ELSE 0
end
You can change the 48 to 2 if you want this to work in days.
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 |
---|---|
109 | |
98 | |
80 | |
64 | |
57 |
User | Count |
---|---|
145 | |
110 | |
91 | |
84 | |
66 |