<?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: Calculating number of business day excluding Country Holidays in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-number-of-business-day-excluding-Country-Holidays/m-p/2201976#M51702</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="98864" data-lia-user-login="Nam" class="lia-mention lia-mention-user"&gt;Nam&lt;/a&gt;&amp;nbsp;- Thank you for the reply. Here is an example of .pbix file&lt;BR /&gt;&lt;A href="https://drive.google.com/file/d/1btNDeG6XkVX2SpXUdFKIRg71zmB998Wk/view?usp=drivesdk" target="_blank" rel="noopener"&gt;https://drive.google.com/file/d/1btNDeG6XkVX2SpXUdFKIRg71zmB998Wk/view?usp=drivesdk&lt;/A&gt;&lt;/P&gt;&lt;P&gt;In the example, the function will exclude weekends and also any dates in the Holiday tables. The end result I wish to achieve is to only calculate Holidays based on the order country.&lt;/P&gt;</description>
    <pubDate>Mon, 22 Nov 2021 17:19:53 GMT</pubDate>
    <dc:creator>PLM2021</dc:creator>
    <dc:date>2021-11-22T17:19:53Z</dc:date>
    <item>
      <title>Calculating number of business day excluding Country Holidays</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-number-of-business-day-excluding-Country-Holidays/m-p/2199216#M51577</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I am trying to figure out how to calculate the number of business days (Age of Order) between the date an order was submitted and today (using a table with &lt;U&gt;list of Holidays per country&lt;/U&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are my tables:&lt;/P&gt;&lt;P&gt;COUNTRY TABLE&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;HOLIDAYS TABLE&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;ORDER TABLE&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am able to add a column by invoking the following custom function – this will exclude week-ends and also any dates in the Holidays table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;= (StartDate as date, Holidays as list) =&amp;gt;
let
                
    EndDate = DateTime.Date(DateTime.LocalNow()),
                // Providing for logic where EndDate is after StartDate
                Start = List.Min({StartDate, EndDate}),
                End = List.Max({StartDate, EndDate}),

                // Switch sign if EndDate is before StartDate
                Sign = if EndDate &amp;lt; StartDate then -1 else 1,

                // Get list of dates between Start- and EndDate
                ListOfDates = List.Dates(Start, Number.From(End - Start) + 1,#duration(1,0,0,0)),

                // if the optional Holidays parameter is used: Keep only those dates in the list that don t occur in the list of Holidays;
                // otherwise continue with previous table
                DeleteHolidays = if Holidays = null then ListOfDates else List.Difference(ListOfDates, List.Transform(Holidays, Date.From )),

                // Select only the first 5 days of the week 
                // The 1 in the 2nd parameter of Date.DayOfWeek makes sure that Monday will be taken as first day of the week
                DeleteWeekends = List.Select(DeleteHolidays, each Date.DayOfWeek(_, 1) &amp;lt; 5 ),

                // Count the number of days (items in the list)
                CountDays = (List.Count(DeleteWeekends) * Sign) - 1
in
CountDays&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The piece that I can’t seem to figure out is how to only apply holidays matching the country of the order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for you help&lt;/P&gt;</description>
      <pubDate>Fri, 19 Nov 2021 20:45:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-number-of-business-day-excluding-Country-Holidays/m-p/2199216#M51577</guid>
      <dc:creator>PLM2021</dc:creator>
      <dc:date>2021-11-19T20:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating number of business day excluding Country Holidays</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-number-of-business-day-excluding-Country-Holidays/m-p/2199364#M51581</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="340107" data-lia-user-login="PLM2021" class="lia-mention lia-mention-user"&gt;PLM2021&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Please post your pbix.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;If you would share your pbix, or dummy up some values in Excel both for current and expected data. Please copy and paste them into your post, rather than doing a picture, we may be able to help you.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Please read this post to get your question answered more quickly:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490" target="_blank"&gt;https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Nathaniel&lt;/P&gt;</description>
      <pubDate>Sat, 20 Nov 2021 00:44:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-number-of-business-day-excluding-Country-Holidays/m-p/2199364#M51581</guid>
      <dc:creator>Nathaniel_C</dc:creator>
      <dc:date>2021-11-20T00:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating number of business day excluding Country Holidays</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-number-of-business-day-excluding-Country-Holidays/m-p/2199584#M51604</link>
      <description>&lt;LI-CODE lang="markup"&gt;#"list of Holidays per country"[Date]&lt;/LI-CODE&gt;
&lt;P&gt;as Holidays parameter to be passed into the function.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Nov 2021 14:28:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-number-of-business-day-excluding-Country-Holidays/m-p/2199584#M51604</guid>
      <dc:creator>CNENFRNL</dc:creator>
      <dc:date>2021-11-20T14:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating number of business day excluding Country Holidays</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-number-of-business-day-excluding-Country-Holidays/m-p/2201976#M51702</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="98864" data-lia-user-login="Nam" class="lia-mention lia-mention-user"&gt;Nam&lt;/a&gt;&amp;nbsp;- Thank you for the reply. Here is an example of .pbix file&lt;BR /&gt;&lt;A href="https://drive.google.com/file/d/1btNDeG6XkVX2SpXUdFKIRg71zmB998Wk/view?usp=drivesdk" target="_blank" rel="noopener"&gt;https://drive.google.com/file/d/1btNDeG6XkVX2SpXUdFKIRg71zmB998Wk/view?usp=drivesdk&lt;/A&gt;&lt;/P&gt;&lt;P&gt;In the example, the function will exclude weekends and also any dates in the Holiday tables. The end result I wish to achieve is to only calculate Holidays based on the order country.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Nov 2021 17:19:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-number-of-business-day-excluding-Country-Holidays/m-p/2201976#M51702</guid>
      <dc:creator>PLM2021</dc:creator>
      <dc:date>2021-11-22T17:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating number of business day excluding Country Holidays</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-number-of-business-day-excluding-Country-Holidays/m-p/2202030#M51705</link>
      <description>&lt;P&gt;Thank you for your reply&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="250150" data-lia-user-login="CNENFRNL" class="lia-mention lia-mention-user"&gt;CNENFRNL&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Holidays parameter does get pass to the function as a list and is being apply to any order. The piece that I can't figure out is how to only apply the Holidays to the matching countries of the order.&lt;/P&gt;&lt;P&gt;I tried passing Holidays as a table rather then a list. This way both columns will be accessible through the function but I am struggling understanding the syntax to parse and compare the country to only apply Holidays for matching order countries. Is it possible to achieve in a single function?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Nov 2021 17:18:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-number-of-business-day-excluding-Country-Holidays/m-p/2202030#M51705</guid>
      <dc:creator>PLM2021</dc:creator>
      <dc:date>2021-11-22T17:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating number of business day excluding Country Holidays</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-number-of-business-day-excluding-Country-Holidays/m-p/2205267#M51868</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="340107" data-lia-user-login="PLM2021" class="lia-mention lia-mention-user"&gt;PLM2021&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the Table.SelectRows to filter the holidays depend on the CountryID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please refer the following code.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    Source = (_Countryid as text , _Holidays as table, StartDate as date) =&amp;gt;
    let 
    
    MatchHolidaysTalbe = Table.SelectRows(_Holidays,each [CountryID] = _Countryid),

    MathcHolidaysColumn = Table.ToColumns(MatchHolidaysTalbe),
    MathcHolidaysList =MathcHolidaysColumn{0},


    EndDate = DateTime.Date(DateTime.LocalNow()),
	// Providing for logic where EndDate is after StartDate
	Start = List.Min({StartDate, EndDate}),
	End = List.Max({StartDate, EndDate}),

	// Switch sign if EndDate is before StartDate
	Sign = if EndDate &amp;lt; StartDate then -1 else 1,

	// Get list of dates between Start- and EndDate
	ListOfDates = List.Dates(Start, Number.From(End - Start) + 1,#duration(1,0,0,0)),

	// if the optional Holidays parameter is used: Keep only those dates in the list that don t occur in the list of Holidays;
	// otherwise continue with previous table
	DeleteHolidays = if MathcHolidaysList = null then ListOfDates else List.Difference(ListOfDates, List.Transform(MathcHolidaysList, Date.From )),

	// Select only the first 5 days of the week 
	// The 1 in the 2nd parameter of Date.DayOfWeek makes sure that Monday will be taken as first day of the week
	DeleteWeekends = List.Select(DeleteHolidays, each Date.DayOfWeek(_, 1) &amp;lt; 5 ),

	// Count the number of days (items in the list)
	CountDays = (List.Count(DeleteWeekends) * Sign) - 1
    in
    CountDays
in
    Source&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In fact, the M function is not a good choice for analyzing data, I recommend DAX.&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;AgeOfOrder_DAX =
VAR _END =
    TODAY()
VAR _START = [SubmittedOn].[Date]
VAR _totalday =
    GENERATESERIES( _START, _END )
VAR _1 =
    GROUPBY(
        FILTER( 'Holidays', [CountryID] = EARLIER( 'Order'[CountryID] ) ),
        [Date]
    )
VAR _2 =
    EXCEPT( _totalday, _1 )
VAR _a =
    ADDCOLUMNS( _2, "weeknum", WEEKDAY( [Value], 2 ) )
RETURN
    COUNTROWS( FILTER( _a, [weeknum] &amp;lt; 6 ) ) - 1
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I put the pbix file in the end you can refer&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;
&lt;P&gt;Community Support Team _ chenwu zhu&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 08:18:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-number-of-business-day-excluding-Country-Holidays/m-p/2205267#M51868</guid>
      <dc:creator>v-chenwuz-msft</dc:creator>
      <dc:date>2021-11-24T08:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating number of business day excluding Country Holidays</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-number-of-business-day-excluding-Country-Holidays/m-p/2206080#M51916</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="320777" data-lia-user-login="v-chenwuz-msft" class="lia-mention lia-mention-user"&gt;v-chenwuz-msft&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thank you for your post. This is exactly what I was looking for.... And I think that it's more appropriate to perform this operation at the dataset level rather then the dataflow.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 15:05:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-number-of-business-day-excluding-Country-Holidays/m-p/2206080#M51916</guid>
      <dc:creator>PLM2021</dc:creator>
      <dc:date>2021-11-24T15:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating number of business day excluding Country Holidays</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-number-of-business-day-excluding-Country-Holidays/m-p/2611078#M75736</link>
      <description>&lt;P&gt;Hi chenwuz,&lt;BR /&gt;This is great! But instead of business days, how can we calculate it at hour level (business hour) using this DAX sample. I tried to modified it, but it didn't work out.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 06:21:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-number-of-business-day-excluding-Country-Holidays/m-p/2611078#M75736</guid>
      <dc:creator>Gabiiiii</dc:creator>
      <dc:date>2022-06-30T06:21:32Z</dc:date>
    </item>
  </channel>
</rss>

