<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Calculate Business hours by countries with different holidays in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Business-hours-by-countries-with-different-holidays/m-p/2611007#M75733</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="390522" data-lia-user-login="Gabiiiii" class="lia-mention lia-mention-user"&gt;Gabiiiii&lt;/a&gt; , Assume it is only weekend , you do not need a holiday calendar&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Work Day =&lt;/P&gt;
&lt;P&gt;Switch( True() ,&lt;/P&gt;
&lt;P&gt;[Country] in {"USA", "UK", "IN", "AUS"} ,&lt;/P&gt;
&lt;P&gt;COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(Table[Start Date],Table[End Date]),"WorkDay", if(WEEKDAY([Date],2) &amp;lt;6,1,0)),[WorkDay] =1)),&lt;/P&gt;
&lt;P&gt;[Country] in {"UAE", "SA"} , // assume having holiday on Friday and Saturday&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(Table[Start Date],Table[End Date]),"WorkDay", if(WEEKDAY([Date],2) in {5,6} ,0,1)),[WorkDay] =1)),&lt;/P&gt;
&lt;P&gt;COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(Table[Start Date],Table[End Date]),"WorkDay", if(WEEKDAY([Date],2) &amp;lt;6,1,0)),[WorkDay] =1))&lt;/P&gt;
&lt;P&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jun 2022 05:44:22 GMT</pubDate>
    <dc:creator>amitchandak</dc:creator>
    <dc:date>2022-06-30T05:44:22Z</dc:date>
    <item>
      <title>Calculate Business hours by countries with different holidays</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Business-hours-by-countries-with-different-holidays/m-p/2610677#M75711</link>
      <description>&lt;P&gt;Hi Power BI Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm replacing all the calender days calculation to business days:&lt;/P&gt;&lt;P&gt;Exclude weekends, exclude holidays in different countries (have a holiday table to store holiday dates for different countries)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I have done some research in the forum, but was still not working.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, I used the method of calculating working hours to get the business hours besides weekends. and then subtract the number of holidays if it happens to be a weekday.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, an error occured as this:&amp;nbsp;&lt;EM&gt;A date column containing duplicate dates was specified in the call to function 'DATESBETWEEN'. This is not supported.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the DAX I currently use:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;businessday = &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;var _END =Fact[completedon]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;var _START =Fact[createdon]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;var _holiday =&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; CALCULATE (&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; SUM (Holidays[Isweekday]),&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; DATESBETWEEN (Holidays[holidaydate],_START,_END),&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; Holidays[countrycode]=EARLIER(Fact[countrycode])&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; )&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;var _workinghours = &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;SUMX(&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; CALCULATETABLE(&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; Dates,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; DATESBETWEEN(Dates[Date],_START,_END),&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; Dates[IsWorkingDay] = TRUE()),&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; MAX(MIN(Dates[End],_END)-MAX(Dates[Start],_START),0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; )&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;return IF(_workinghours-_holiday&amp;gt;0,_workinghours-_holiday,BLANK())&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 01 Jul 2022 06:04:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Business-hours-by-countries-with-different-holidays/m-p/2610677#M75711</guid>
      <dc:creator>Gabiiiii</dc:creator>
      <dc:date>2022-07-01T06:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Business hours by countries with different holidays</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Business-hours-by-countries-with-different-holidays/m-p/2610697#M75713</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="390522" data-lia-user-login="Gabiiiii" class="lia-mention lia-mention-user"&gt;Gabiiiii&lt;/a&gt; , If you need &lt;/P&gt;
&lt;P&gt;Business Days&lt;/P&gt;
&lt;P&gt;Work Day = COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(Table[Start Date],Table[End Date]),"WorkDay", if(WEEKDAY([Date],2) &amp;lt;6,1,0)),[WorkDay] =1))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need business hours check solution from Matt&lt;/P&gt;
&lt;P&gt;&lt;A href="https://exceleratorbi.com.au/calculating-business-hours-using-dax/" target="_blank"&gt;https://exceleratorbi.com.au/calculating-business-hours-using-dax/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 02:04:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Business-hours-by-countries-with-different-holidays/m-p/2610697#M75713</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2022-06-30T02:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Business hours by countries with different holidays</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Business-hours-by-countries-with-different-holidays/m-p/2610840#M75723</link>
      <description>&lt;P&gt;Thank you amitchandak, the link you share is very helpful. However, I still cannot figure out how to calculate the business days by different countries as they have different holidays.&lt;/P&gt;&lt;P&gt;I change my code to this, it would return the wrong value.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;TAT = &lt;BR /&gt;var _END =Table[completedon]&lt;BR /&gt;&lt;BR /&gt;var _START =Table[createdon]&lt;BR /&gt;&lt;BR /&gt;var _totalday = GENERATESERIES(_START,IF(ISBLANK(_END),0,_END))&lt;BR /&gt;&lt;BR /&gt;var _1 = GROUPBY(FILTER(Holidays,Holidays[businessunit]=EARLIER(Fact[businessunit])),Holidays[crc5e_holidaydate])&lt;BR /&gt;&lt;BR /&gt;var _2 = EXCEPT(_totalday,_1) &lt;BR /&gt;&lt;BR /&gt;var _a = ADDCOLUMNS(_2,"weeknum",WEEKDAY([Value],2))&lt;/SPAN&gt;&lt;/PRE&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;var _workinghours = &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;SUMX(&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; FILTER(_a,[weeknum]&amp;lt;6),&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; MAX(MIN(hsbc_CLTask[clwft_completedon].[Date],_END)-MAX(hsbc_CLTask[createdon].[Date],_START),0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; )&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;return _workinghours&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 30 Jun 2022 03:34:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Business-hours-by-countries-with-different-holidays/m-p/2610840#M75723</guid>
      <dc:creator>Gabiiiii</dc:creator>
      <dc:date>2022-06-30T03:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Business hours by countries with different holidays</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Business-hours-by-countries-with-different-holidays/m-p/2611007#M75733</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="390522" data-lia-user-login="Gabiiiii" class="lia-mention lia-mention-user"&gt;Gabiiiii&lt;/a&gt; , Assume it is only weekend , you do not need a holiday calendar&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Work Day =&lt;/P&gt;
&lt;P&gt;Switch( True() ,&lt;/P&gt;
&lt;P&gt;[Country] in {"USA", "UK", "IN", "AUS"} ,&lt;/P&gt;
&lt;P&gt;COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(Table[Start Date],Table[End Date]),"WorkDay", if(WEEKDAY([Date],2) &amp;lt;6,1,0)),[WorkDay] =1)),&lt;/P&gt;
&lt;P&gt;[Country] in {"UAE", "SA"} , // assume having holiday on Friday and Saturday&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(Table[Start Date],Table[End Date]),"WorkDay", if(WEEKDAY([Date],2) in {5,6} ,0,1)),[WorkDay] =1)),&lt;/P&gt;
&lt;P&gt;COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(Table[Start Date],Table[End Date]),"WorkDay", if(WEEKDAY([Date],2) &amp;lt;6,1,0)),[WorkDay] =1))&lt;/P&gt;
&lt;P&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 05:44:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Business-hours-by-countries-with-different-holidays/m-p/2611007#M75733</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2022-06-30T05:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Business hours by countries with different holidays</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Business-hours-by-countries-with-different-holidays/m-p/2613387#M75859</link>
      <description>&lt;P&gt;Hi amitchandak,&lt;/P&gt;&lt;P&gt;Things still didn't work out. Please check my updated post. Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jul 2022 06:05:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Business-hours-by-countries-with-different-holidays/m-p/2613387#M75859</guid>
      <dc:creator>Gabiiiii</dc:creator>
      <dc:date>2022-07-01T06:05:33Z</dc:date>
    </item>
  </channel>
</rss>

