<?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: dateDiff in weekdays function in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/dateDiff-in-weekdays-function/m-p/2564236#M73022</link>
    <description>&lt;P&gt;Thanks so much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The original function works fine now that all the null values out of closureDate have been replaced by DateTime.LocalNow&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again ^^&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Jun 2022 14:20:08 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-06-07T14:20:08Z</dc:date>
    <item>
      <title>dateDiff in weekdays function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/dateDiff-in-weekdays-function/m-p/2563060#M72969</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i've been using the following function to calculate the date difference in weekdays between 2 columns (creationDate, closureDate);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;= (InitialDate as date, FinalDate as date ) as number =&amp;gt;&lt;BR /&gt;let&lt;BR /&gt;DaysBetweenDates = Duration.Days(FinalDate-InitialDate),&lt;BR /&gt;DaysList = List.Dates(List.Min({InitialDate,FinalDate}),Number.Abs(DaysBetweenDates)+1, Duration.From(1)),&lt;BR /&gt;WeekDaysList = List.Select(DaysList, each (Date.DayOfWeek(_, Day.Monday) &amp;lt; 5) ),&lt;BR /&gt;WorkingDays = (if DaysBetweenDates &amp;lt; 0 then -1 else 1) * List.Count(WeekDaysList)&lt;BR /&gt;in&lt;BR /&gt;WorkingDays&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The function lets me select 2 columns, but since i'm trying to calculate&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;processing&lt;/EM&gt; &lt;EM&gt;time&lt;/EM&gt;&lt;/STRONG&gt; and i'm only using creation- and closureDate, i can only calculate the processing time of tickets already closed. I'm trying to get a third column into the mix that takes the currentDate if closureDate is empty, but i can't seem to get that IF statement to work at all &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&amp;nbsp; anyone knows the solution?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 07:30:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/dateDiff-in-weekdays-function/m-p/2563060#M72969</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-06-07T07:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: dateDiff in weekdays function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/dateDiff-in-weekdays-function/m-p/2563343#M72980</link>
      <description>&lt;P&gt;This is a PQ question Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; But take a look at this:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;= (InitialDate as date, FinalDate as date) as number =&amp;gt;
let
FinalDateCheck = Number.From(each if [Final Date] = null then Date.From(DateTime.LocalNow()) else [Final Date]),
DaysBetweenDates = Duration.Days(FinalDateCheck-InitialDate),
DaysList = List.Dates(List.Min({InitialDate,FinalDateCheck}),Number.Abs(DaysBetweenDates)+1, Duration.From(1)),
WeekDaysList = List.Select(DaysList, each (Date.DayOfWeek(_, Day.Monday) &amp;lt; 5) ),
WorkingDays = (if DaysBetweenDates &amp;lt; 0 then -1 else 1) * List.Count(WeekDaysList)
in
WorkingDays&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I modified your function with a simple if statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 10:04:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/dateDiff-in-weekdays-function/m-p/2563343#M72980</guid>
      <dc:creator>ChrisClever</dc:creator>
      <dc:date>2022-06-07T10:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: dateDiff in weekdays function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/dateDiff-in-weekdays-function/m-p/2563562#M72997</link>
      <description>&lt;P&gt;Hi there &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="319692" data-lia-user-login="ChrisClever" class="lia-mention lia-mention-user"&gt;ChrisClever&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just noticed that i had selected the wrong forum; oops :0&lt;/P&gt;&lt;P&gt;I've tried the adjustment to the function, but it gives the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DataFormat.Error: can't convert to Number.&lt;BR /&gt;Details:&lt;BR /&gt;[Function]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm guessing there is something wrong with the data types somewhere, so i changed the intialdate and finaldate to datetime in the first line, but it hasn't fixed the error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i'm not quite sure what exaclty can't be converted to number &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 10:19:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/dateDiff-in-weekdays-function/m-p/2563562#M72997</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-06-07T10:19:28Z</dc:date>
    </item>
    <item>
      <title>Re: dateDiff in weekdays function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/dateDiff-in-weekdays-function/m-p/2563586#M73000</link>
      <description>&lt;P&gt;Did you copy and paste the entire code?&lt;/P&gt;&lt;P&gt;My guess is you've just added the FinalDateCheck line without modifying the rest of the code &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Take a close look - you need to change FinalDate to FinalDateCheck in your calculations.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 10:15:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/dateDiff-in-weekdays-function/m-p/2563586#M73000</guid>
      <dc:creator>ChrisClever</dc:creator>
      <dc:date>2022-06-07T10:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: dateDiff in weekdays function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/dateDiff-in-weekdays-function/m-p/2563702#M73003</link>
      <description>&lt;P&gt;yup, i've copied all of the code, and tried all of the data types.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The function should give dateDiff in weekdays as whole numbers.&lt;/P&gt;&lt;P&gt;Still unclear what causes the conversion to number error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried changing line 3;&lt;/P&gt;&lt;P&gt;FinalDateCheck = Number.From(each.....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to:&lt;/P&gt;&lt;P&gt;FinalDateCheck = Date.from(each....&lt;/P&gt;&lt;P&gt;and now it gives the same DataFormat.Error except for number it now says date:&lt;/P&gt;&lt;P&gt;can't convert to date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;lastly i've removed the spaces between Final Date in line 3, sadly without effect.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 11:39:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/dateDiff-in-weekdays-function/m-p/2563702#M73003</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-06-07T11:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: dateDiff in weekdays function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/dateDiff-in-weekdays-function/m-p/2563980#M73012</link>
      <description>&lt;P&gt;Ok,&lt;/P&gt;&lt;P&gt;So the problem here is the null value in the FinalDate Column. The easy fix would be to replace the nulls with the current date before adding the custom function column. And then your code should be working just fine.&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;#"Replace Value" = Table.ReplaceValue(#"Changed type",null,Date.From(DateTime.LocalNow()),Replacer.ReplaceValue,{"Final Date"})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 13:01:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/dateDiff-in-weekdays-function/m-p/2563980#M73012</guid>
      <dc:creator>ChrisClever</dc:creator>
      <dc:date>2022-06-07T13:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: dateDiff in weekdays function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/dateDiff-in-weekdays-function/m-p/2564236#M73022</link>
      <description>&lt;P&gt;Thanks so much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The original function works fine now that all the null values out of closureDate have been replaced by DateTime.LocalNow&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again ^^&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 14:20:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/dateDiff-in-weekdays-function/m-p/2564236#M73022</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-06-07T14:20:08Z</dc:date>
    </item>
  </channel>
</rss>

