<?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 DATEDIFF() not giving the right results in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-not-giving-the-right-results/m-p/4274125#M169561</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;I'm having trouble writing a measure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two tables:&lt;/P&gt;&lt;P&gt;- One that tells me when a design process is due (named&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;"Date Initiale (Demandée com)"&lt;/SPAN&gt;&lt;SPAN&gt;) and the actual date it has been delivered at (named "Task Completion date").&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;- The other one, is my Calendar that has two boolean columns that tell me wether a given day is a weekend (named "Jours OFF") or holiday (named "Non travaillé"). With 1 if it is and 0, if not.&lt;BR /&gt;&lt;BR /&gt;I want to figure out how long my design processes have been late (due date is passed but task completion date for the given process is after the due date or is still empty). So the logic I followed is:&lt;/P&gt;&lt;P&gt;- If a design process has been delivered late, I use it's task completion date for the calculation.&lt;/P&gt;&lt;P&gt;- If it's still ongoing (meaninng no task completion exist) I'll use today as the end date for the calculation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Then I use DateDiff to identify the difference in days between the due date and the end date. To that result, I remove all weekends and holidays that may be included in that frame to only count working days.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is, the results aren't correct at all and it seems DateDiff might be the reason. Though, I'm not sure why it's the case.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example here's a table with the results of my measure for all ongoing late process (delay(days)) with their due dates. As they all don't have a completion date, I'm using Today as end date to make my calculations:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Design process code&lt;/TD&gt;&lt;TD&gt;Delay(days)&lt;/TD&gt;&lt;TD&gt;Year&lt;/TD&gt;&lt;TD&gt;Month&lt;/TD&gt;&lt;TD&gt;Day&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;XXXXXXXX&lt;/TD&gt;&lt;TD&gt;23&lt;/TD&gt;&lt;TD&gt;2024&lt;/TD&gt;&lt;TD&gt;Oct&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;YYYYYYYY&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;2024&lt;/TD&gt;&lt;TD&gt;Sept&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ZZZZZZZZ&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;2024&lt;/TD&gt;&lt;TD&gt;Oct&lt;/TD&gt;&lt;TD&gt;18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;VVVVVVV&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;2024&lt;/TD&gt;&lt;TD&gt;Oct&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;WWWWW&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2024&lt;/TD&gt;&lt;TD&gt;Oct&lt;/TD&gt;&lt;TD&gt;31&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;TTTTTTTTT&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2024&lt;/TD&gt;&lt;TD&gt;Nov&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The process T shouldn't be 2 days late but 3 since we're November 7th and the process X shouldn't be only 20 days from September to today as November 1st was the sole holiday during that period.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Here is the measure:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;Retard par Notification = 

VAR DateInitiale = MAX( 'Tasks details'[Date Initiale (Demandée com)])
VAR TaskCompletionDate = MAX( 'Tasks details'[Task Completion date])

VAR DateActuelle = MAX('_Calendrier'[Date])
VAR DateFin = IF(NOT(ISBLANK(TaskCompletionDate)), TaskCompletionDate, DateActuelle)

-- here is to manage the holidays and weekends 
VAR JoursOff = 
    CALCULATE(
        COUNT('_Calendrier'[Date]),
        '_Calendrier'[Date] &amp;gt;= DateInitiale &amp;amp;&amp;amp; 
        '_Calendrier'[Date] &amp;lt;= DateFin &amp;amp;&amp;amp;
        ('_Calendrier'[Jours OFF] = 1 || '_Calendrier'[Non travaillé] = 1)
    )

VAR RetardNet = DATEDIFF(DateInitiale, DateFin, DAY) +1 - JoursOff 

RETURN 
    IF(RetardNet &amp;gt; 0, RetardNet, BLANK())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Nov 2024 14:09:27 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-11-07T14:09:27Z</dc:date>
    <item>
      <title>DATEDIFF() not giving the right results</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-not-giving-the-right-results/m-p/4274125#M169561</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;I'm having trouble writing a measure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two tables:&lt;/P&gt;&lt;P&gt;- One that tells me when a design process is due (named&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;"Date Initiale (Demandée com)"&lt;/SPAN&gt;&lt;SPAN&gt;) and the actual date it has been delivered at (named "Task Completion date").&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;- The other one, is my Calendar that has two boolean columns that tell me wether a given day is a weekend (named "Jours OFF") or holiday (named "Non travaillé"). With 1 if it is and 0, if not.&lt;BR /&gt;&lt;BR /&gt;I want to figure out how long my design processes have been late (due date is passed but task completion date for the given process is after the due date or is still empty). So the logic I followed is:&lt;/P&gt;&lt;P&gt;- If a design process has been delivered late, I use it's task completion date for the calculation.&lt;/P&gt;&lt;P&gt;- If it's still ongoing (meaninng no task completion exist) I'll use today as the end date for the calculation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Then I use DateDiff to identify the difference in days between the due date and the end date. To that result, I remove all weekends and holidays that may be included in that frame to only count working days.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is, the results aren't correct at all and it seems DateDiff might be the reason. Though, I'm not sure why it's the case.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example here's a table with the results of my measure for all ongoing late process (delay(days)) with their due dates. As they all don't have a completion date, I'm using Today as end date to make my calculations:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Design process code&lt;/TD&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n't be 2 days late but 3 since we're November 7th and the process X shouldn't be only 20 days from September to today as November 1st was the sole holiday during that period.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Here is the measure:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;Retard par Notification = 

VAR DateInitiale = MAX( 'Tasks details'[Date Initiale (Demandée com)])
VAR TaskCompletionDate = MAX( 'Tasks details'[Task Completion date])

VAR DateActuelle = MAX('_Calendrier'[Date])
VAR DateFin = IF(NOT(ISBLANK(TaskCompletionDate)), TaskCompletionDate, DateActuelle)

-- here is to manage the holidays and weekends 
VAR JoursOff = 
    CALCULATE(
        COUNT('_Calendrier'[Date]),
        '_Calendrier'[Date] &amp;gt;= DateInitiale &amp;amp;&amp;amp; 
        '_Calendrier'[Date] &amp;lt;= DateFin &amp;amp;&amp;amp;
        ('_Calendrier'[Jours OFF] = 1 || '_Calendrier'[Non travaillé] = 1)
    )

VAR RetardNet = DATEDIFF(DateInitiale, DateFin, DAY) +1 - JoursOff 

RETURN 
    IF(RetardNet &amp;gt; 0, RetardNet, BLANK())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2024 14:09:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-not-giving-the-right-results/m-p/4274125#M169561</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-07T14:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: DATEDIFF() not giving the right results</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-not-giving-the-right-results/m-p/4274147#M169563</link>
      <description>&lt;P&gt;Try using TODAY() for DateActuelle&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2024 13:45:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-not-giving-the-right-results/m-p/4274147#M169563</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2024-11-07T13:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: DATEDIFF() not giving the right results</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-not-giving-the-right-results/m-p/4274179#M169568</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I did just that and it works now. Thank you!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2024 14:07:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-not-giving-the-right-results/m-p/4274179#M169568</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-07T14:07:57Z</dc:date>
    </item>
  </channel>
</rss>

