<?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: Help with calculating the number of days in between 2 date columns with a specific requirement in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-calculating-the-number-of-days-in-between-2-date/m-p/4008369#M157367</link>
    <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your question, here is the method I provided:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Table"&lt;/P&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;
&lt;P&gt;First, you need to add an index column to the power query.&lt;/P&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;
&lt;P&gt;Creates a new column that looks up the date with alias 33.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Mark 33 DATE = 
IF(
         ('Table'[New Value] = 33 &amp;amp;&amp;amp; ISBLANK('Table'[Old Value]))
        ||
        'Table'[Old Value] = 33
    ,
    'Table'[Update 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;
&lt;P&gt;Create a column or a measure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Column = 
var currentIndex = IF(
        'Table'[Mark 33 DATE] = 'Table'[Update Date]
        &amp;amp;&amp;amp;
        'Table'[Old Value] = 33
    ,
    'Table'[Index]
)
var previousDate = 
CALCULATE(
    MAX('Table'[Mark 33 DATE]), 
    FILTER(
        'Table', 
        'Table'[Index] &amp;lt; currentIndex
    )
)
var currentDate = 
CALCULATE(
    MAX('Table'[Mark 33 DATE]), 
    FILTER(
        'Table', 
        'Table'[Index] = currentIndex
    )
)
RETURN DATEDIFF(previousDate, currentDate, DAY)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;OR&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Measure = 
var currentIndex = 
IF(
    SELECTEDVALUE('Table'[Mark 33 DATE]) = SELECTEDVALUE('Table'[Update Date])
    &amp;amp;&amp;amp;
    SELECTEDVALUE('Table'[Old Value]) = 33,
    SELECTEDVALUE('Table'[Index])
)
var previousDate = 
CALCULATE(
    MAX('Table'[Mark 33 DATE]), 
    FILTER(
        ALL('Table'), 
        'Table'[Index] &amp;lt; currentIndex
    )
)
var currentDate = 
CALCULATE(
    MAX('Table'[Mark 33 DATE]), 
    FILTER(
        ALL('Table'), 
        'Table'[Index] = currentIndex
    )
)
RETURN DATEDIFF(previousDate, currentDate, DAY)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Here is the result.&lt;/P&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;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Nono Chen&lt;/P&gt;
&lt;P&gt;If this &lt;STRONG&gt;&lt;EM&gt;post&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;helps, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;</description>
    <pubDate>Tue, 25 Jun 2024 06:24:47 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-06-25T06:24:47Z</dc:date>
    <item>
      <title>Help with calculating the number of days in between 2 date columns with a specific requirement</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-calculating-the-number-of-days-in-between-2-date/m-p/4007487#M157002</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the below data set in a Pbix file. Basically what I need it to count the number of days an order was under a specific delivery block (33). On this dataset one order may go under many different blocks, but I only need to see the duration it was under block 33. Looking at the Data below, we can see the order was place on block 33 firstly on 03/14 and taken off 03/15, then placed on 33 again on 03/20 and taken 0ff on 03/22, then once again placed under 33 on 03/28 and taken off 04/01. That would total 7 days under block 33. Note that the old Value Field can be empty or it can have another value, however, we only want to see when the date the New Value changes to 33 and the date it changes from 33 into something else so we can calculate the number of days for that specific action. Any help would be deeply appreciated. Thank you.&lt;/P&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>Mon, 24 Jun 2024 17:37:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-calculating-the-number-of-days-in-between-2-date/m-p/4007487#M157002</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-06-24T17:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Help with calculating the number of days in between 2 date columns with a specific requirement</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-calculating-the-number-of-days-in-between-2-date/m-p/4008369#M157367</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your question, here is the method I provided:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Table"&lt;/P&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;
&lt;P&gt;First, you need to add an index column to the power query.&lt;/P&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;
&lt;P&gt;Creates a new column that looks up the date with alias 33.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Mark 33 DATE = 
IF(
         ('Table'[New Value] = 33 &amp;amp;&amp;amp; ISBLANK('Table'[Old Value]))
        ||
        'Table'[Old Value] = 33
    ,
    'Table'[Update 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;
&lt;P&gt;Create a column or a measure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Column = 
var currentIndex = IF(
        'Table'[Mark 33 DATE] = 'Table'[Update Date]
        &amp;amp;&amp;amp;
        'Table'[Old Value] = 33
    ,
    'Table'[Index]
)
var previousDate = 
CALCULATE(
    MAX('Table'[Mark 33 DATE]), 
    FILTER(
        'Table', 
        'Table'[Index] &amp;lt; currentIndex
    )
)
var currentDate = 
CALCULATE(
    MAX('Table'[Mark 33 DATE]), 
    FILTER(
        'Table', 
        'Table'[Index] = currentIndex
    )
)
RETURN DATEDIFF(previousDate, currentDate, DAY)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;OR&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Measure = 
var currentIndex = 
IF(
    SELECTEDVALUE('Table'[Mark 33 DATE]) = SELECTEDVALUE('Table'[Update Date])
    &amp;amp;&amp;amp;
    SELECTEDVALUE('Table'[Old Value]) = 33,
    SELECTEDVALUE('Table'[Index])
)
var previousDate = 
CALCULATE(
    MAX('Table'[Mark 33 DATE]), 
    FILTER(
        ALL('Table'), 
        'Table'[Index] &amp;lt; currentIndex
    )
)
var currentDate = 
CALCULATE(
    MAX('Table'[Mark 33 DATE]), 
    FILTER(
        ALL('Table'), 
        'Table'[Index] = currentIndex
    )
)
RETURN DATEDIFF(previousDate, currentDate, DAY)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Here is the result.&lt;/P&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;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Nono Chen&lt;/P&gt;
&lt;P&gt;If this &lt;STRONG&gt;&lt;EM&gt;post&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;helps, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2024 06:24:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-calculating-the-number-of-days-in-between-2-date/m-p/4008369#M157367</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-06-25T06:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: Help with calculating the number of days in between 2 date columns with a specific requirement</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-calculating-the-number-of-days-in-between-2-date/m-p/4041146#M160234</link>
      <description>&lt;P&gt;Thank you very much Nuno. We mad a small adaptation here but it worked. I appreciate the help.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jul 2024 16:19:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-calculating-the-number-of-days-in-between-2-date/m-p/4041146#M160234</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-07-14T16:19:10Z</dc:date>
    </item>
  </channel>
</rss>

