Forum Discussion
Calculating Elapsed Business Hours Using DAX
- 4 years ago
Hi Anonymous
Try this formula
Business Hours_2 = VAR _Start = 'Incident Fact'[createdon] VAR _End = 'Incident Fact'[Case_Solved] VAR _Country = 'Incident Fact'[Country] VAR _Workhours = SUMX ( CALCULATETABLE ( 'Calendar', DATESBETWEEN ( 'Calendar'[Date], _Start, _End ), SWITCH ( _Country, "Spain", 'Calendar'[Working Day Spain] = 1, "Portugal", 'Calendar'[Working Day Portugal] = 1 ) ), MAX ( MIN ( 'Calendar'[End], _End ) - MAX ( 'Calendar'[Start], _Start ), 0 ) * 24 ) RETURN IF ( _Workhours, _Workhours, 0 )Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
Hi Amit,
thanks for your response, i used the way you mentioned as well, it works, but the issue i face is how to include the following condition into DAX.
I have the 'Incident_Fact' Table with all the cases and there is column with countries in which the case was created.
And i have the 'Calendar' Table where columns per country indicate if this particular Date is holiday or Weekend.
If 'Incident'[country_name] = "Portugal" then use 'Calendar'[Working Day Portugal] =1 etc
Hi Anonymous
Try this formula
Business Hours_2 =
VAR _Start = 'Incident Fact'[createdon]
VAR _End = 'Incident Fact'[Case_Solved]
VAR _Country = 'Incident Fact'[Country]
VAR _Workhours =
SUMX (
CALCULATETABLE (
'Calendar',
DATESBETWEEN ( 'Calendar'[Date], _Start, _End ),
SWITCH (
_Country,
"Spain", 'Calendar'[Working Day Spain] = 1,
"Portugal", 'Calendar'[Working Day Portugal] = 1
)
),
MAX ( MIN ( 'Calendar'[End], _End ) - MAX ( 'Calendar'[Start], _Start ), 0 ) * 24
)
RETURN
IF ( _Workhours, _Workhours, 0 )
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
- Anonymous4 years agoNot applicable
It works, great. Thanks for help!
- Alpesh2 years agoHelper I
Hi, I know this is an old thread, but how could the same be modified for every country, where most countries have different start and end times and holidays?