<?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 Time difference between rows in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Time-difference-between-rows/m-p/2846753#M91103</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been trying to solve my problem for a few days, but even with research on the forum, I can't seem to make it work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Concept :&lt;/P&gt;&lt;P&gt;I get pings from 7 machines at varying delays. These looks like this :&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;I am trying to calculate the availability of these machines in the last days. To date, I created a pie-chart that looked at the number of ping occurrences for each of the machine statuses (0-2-3-4-5-6, meaning stopped, running, in alarm, etc). The problem is that if the machine pings status "6" 60 times (every minute) for an hour, then pings status "2" once and then goes an hour without a ping, the pie-chart will show that status "6 " takes up 60 times more space, when it should be equal.&lt;BR /&gt;So I need to calculate the difference (in seconds) of time between two lines, &lt;U&gt;per machine&lt;/U&gt;, since the last ping. Like this :&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;I tried a couple of measure and calculated column, and the closest I got is this :&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;TimedifferenceMeasure = 
VAR CurrentIndex =
    MAX ( machine_status[id] )
VAR PreviousIndex =
    CALCULATE (
        MAX ( machine_status[id] ),
        FILTER ( machine_status, machine_status[id] &amp;lt; CurrentIndex )
    )
VAR difference =
    DATEDIFF (
        CALCULATE (
            MAX ( machine_status[Creation Time] ),
            FILTER ( ALL ( machine_status ), machine_status[id] = PreviousIndex )
        ),
        CALCULATE (
            MAX ( machine_status[Creation Time] ),
            FILTER ( ALL ( machine_status ), machine_status[id] = CurrentIndex )
        ),
        SECOND
    )
RETURN
    IF ( difference &amp;gt; 43200, 43200, difference )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(The purpose of the 43200 at the end is to limit the time per status to 12 hours. Skip that, the machine is usually closed)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;But it doesn't give me what I want. It seems to calculated only the last&amp;nbsp;occurrence, meaning that frequents status get under-represented.&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the link to my file :&lt;/P&gt;&lt;P&gt;&lt;A href="https://umanomed-my.sharepoint.com/:u:/g/personal/anthony_laroche_umanomedical_com/EdvcvOQ7WWRMsPGb5iXmEj8BIf7WOpwn-PVyJOs1BZDE4Q?e=7Q2TyT" target="_blank" rel="noopener"&gt;https://umanomed-my.sharepoint.com/:u:/g/personal/anthony_laroche_umanomedical_com/EdvcvOQ7WWRMsPGb5iXmEj8BIf7WOpwn-PVyJOs1BZDE4Q?e=7Q2TyT&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you !&lt;/P&gt;</description>
    <pubDate>Mon, 17 Oct 2022 14:18:46 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-10-17T14:18:46Z</dc:date>
    <item>
      <title>Time difference between rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Time-difference-between-rows/m-p/2846753#M91103</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been trying to solve my problem for a few days, but even with research on the forum, I can't seem to make it work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Concept :&lt;/P&gt;&lt;P&gt;I get pings from 7 machines at varying delays. These looks like this :&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;I am trying to calculate the availability of these machines in the last days. To date, I created a pie-chart that looked at the number of ping occurrences for each of the machine statuses (0-2-3-4-5-6, meaning stopped, running, in alarm, etc). The problem is that if the machine pings status "6" 60 times (every minute) for an hour, then pings status "2" once and then goes an hour without a ping, the pie-chart will show that status "6 " takes up 60 times more space, when it should be equal.&lt;BR /&gt;So I need to calculate the difference (in seconds) of time between two lines, &lt;U&gt;per machine&lt;/U&gt;, since the last ping. Like this :&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;I tried a couple of measure and calculated column, and the closest I got is this :&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;TimedifferenceMeasure = 
VAR CurrentIndex =
    MAX ( machine_status[id] )
VAR PreviousIndex =
    CALCULATE (
        MAX ( machine_status[id] ),
        FILTER ( machine_status, machine_status[id] &amp;lt; CurrentIndex )
    )
VAR difference =
    DATEDIFF (
        CALCULATE (
            MAX ( machine_status[Creation Time] ),
            FILTER ( ALL ( machine_status ), machine_status[id] = PreviousIndex )
        ),
        CALCULATE (
            MAX ( machine_status[Creation Time] ),
            FILTER ( ALL ( machine_status ), machine_status[id] = CurrentIndex )
        ),
        SECOND
    )
RETURN
    IF ( difference &amp;gt; 43200, 43200, difference )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(The purpose of the 43200 at the end is to limit the time per status to 12 hours. Skip that, the machine is usually closed)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;But it doesn't give me what I want. It seems to calculated only the last&amp;nbsp;occurrence, meaning that frequents status get under-represented.&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the link to my file :&lt;/P&gt;&lt;P&gt;&lt;A href="https://umanomed-my.sharepoint.com/:u:/g/personal/anthony_laroche_umanomedical_com/EdvcvOQ7WWRMsPGb5iXmEj8BIf7WOpwn-PVyJOs1BZDE4Q?e=7Q2TyT" target="_blank" rel="noopener"&gt;https://umanomed-my.sharepoint.com/:u:/g/personal/anthony_laroche_umanomedical_com/EdvcvOQ7WWRMsPGb5iXmEj8BIf7WOpwn-PVyJOs1BZDE4Q?e=7Q2TyT&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you !&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 14:18:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Time-difference-between-rows/m-p/2846753#M91103</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-10-17T14:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: Time difference between rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Time-difference-between-rows/m-p/2847573#M91165</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;Does this one &lt;A href="https://www.tackytech.blog/how-to-crack-the-mystery-of-the-mighty-dax/#calculate-the-date-difference-between-rows-over-the-whole-table-or-grouped-by-a-status" target="_self"&gt;here&lt;/A&gt; help you?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ranking Column in your case should be the [Created On] column, where as the Grouping Column is [id]&lt;/P&gt;
&lt;PRE&gt;DateDiffColumnWithoutIndex = 
DATEDIFF (
   'TableName'[RankingColumn],
    CALCULATE (
        MIN ( 'TableName'[RankingColumn] ),
        FILTER ( 'TableName', 'TableName'[RankingColumn]  &amp;gt; EARLIER ( 'TableName'[RankingColumn]  ) ),
        FILTER ( 'TableName', 'TableName'[GroupingColumn] = EARLIER ( 'TableName'[GroupingColumn] ) )
    ),
    SECOND
)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Doing this in a calculated column might take quite some resources and time. Maybe consider adding this column in Power Query instead. This one &lt;A href="https://www.tackytech.blog/how-to-swiftly-take-over-power-query/#calculate-difference-between-rows" target="_self"&gt;here&lt;/A&gt;, might help you in that case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me know if this helps!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/Tom&lt;BR /&gt;&lt;A href="https://www.tackytech.blog/" target="_blank"&gt;https://www.tackytech.blog/&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://www.instagram.com/tackytechtom/" target="_blank"&gt;https://www.instagram.com/tackytechtom/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 20:37:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Time-difference-between-rows/m-p/2847573#M91165</guid>
      <dc:creator>tackytechtom</dc:creator>
      <dc:date>2022-10-17T20:37:51Z</dc:date>
    </item>
    <item>
      <title>Re: Time difference between rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Time-difference-between-rows/m-p/2851726#M91444</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;A href="https://community.powerbi.com/t5/user/viewprofilepage/user-id/353745" target="_self"&gt;&lt;SPAN class=""&gt;tackytechtom&lt;/SPAN&gt;&lt;/A&gt;&amp;nbsp;!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ended up doing it in Power Query like in your link. A couple changes to adapt to my situation and it works now !&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2022 15:33:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Time-difference-between-rows/m-p/2851726#M91444</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-10-19T15:33:07Z</dc:date>
    </item>
  </channel>
</rss>

