<?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: Calculate time difference between specific rows in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-time-difference-between-specific-rows/m-p/2042905#M45877</link>
    <description>&lt;P&gt;Hello, it would be 06:59&lt;/P&gt;</description>
    <pubDate>Fri, 27 Aug 2021 12:24:42 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-08-27T12:24:42Z</dc:date>
    <item>
      <title>Calculate time difference between specific rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-time-difference-between-specific-rows/m-p/2042738#M45871</link>
      <description>&lt;P&gt;Hello Power BI Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was hoping you may offer some help to a novice Power BI User.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to calculate how long a pump has been running for. If 'Pump1 RN' = 1 that means it is running, if 'Pump1 RN' = 0 it means it isn't running.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I work out the total time that the pump has been running?&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 12:36:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-time-difference-between-specific-rows/m-p/2042738#M45871</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-08-27T12:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time difference between specific rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-time-difference-between-specific-rows/m-p/2042882#M45875</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;If the pump was running at 06:00 but not at 07:00, what is the assumption about the time at which it stopped running? 06:01? 06:59?&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 12:11:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-time-difference-between-specific-rows/m-p/2042882#M45875</guid>
      <dc:creator>Jos_Woolley</dc:creator>
      <dc:date>2021-08-27T12:11:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time difference between specific rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-time-difference-between-specific-rows/m-p/2042905#M45877</link>
      <description>&lt;P&gt;Hello, it would be 06:59&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 12:24:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-time-difference-between-specific-rows/m-p/2042905#M45877</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-08-27T12:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time difference between specific rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-time-difference-between-specific-rows/m-p/2042911#M45878</link>
      <description>&lt;P&gt;Then since your &lt;STRONG&gt;Date.Time &lt;/STRONG&gt;intervals are consistenly of length 1 hour, you can just sum the&amp;nbsp;&lt;STRONG&gt;Pump 1 RN&lt;/STRONG&gt; column. If in reality the Date.Time intervals are not as you posted, please post a more realistic example. Also, perhaps confirm your expected result for the sample data you posted.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 12:34:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-time-difference-between-specific-rows/m-p/2042911#M45878</guid>
      <dc:creator>Jos_Woolley</dc:creator>
      <dc:date>2021-08-27T12:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time difference between specific rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-time-difference-between-specific-rows/m-p/2042921#M45880</link>
      <description>&lt;P&gt;Hi Jos, yes sorry I understand what you mean. I have updated the post with a more realistic example of the data. The pump is/isn't running until the next time stamp. For example, the pump has ran for a total of 13hrs and 57 minutes from&amp;nbsp;01/04/2020 00:00:00 to&amp;nbsp;01/05/2020 02:30:00&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 12:42:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-time-difference-between-specific-rows/m-p/2042921#M45880</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-08-27T12:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time difference between specific rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-time-difference-between-specific-rows/m-p/2043796#M45900</link>
      <description>&lt;P&gt;Ok, thanks. Try this measure:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;MyMeasure =
VAR MyTable =
    ADDCOLUMNS (
        'Table',
        "Previous Date.Time",
            CALCULATE (
                MAX ( 'Table'[Date.Time] ),
                FILTER ( 'Table', 'Table'[Date.Time] &amp;lt; EARLIER ( 'Table'[Date.Time] ) )
            ),
        "Previous Pump 1 RN",
            LOOKUPVALUE (
                'Table'[Pump 1 RN],
                'Table'[Date.Time],
                    CALCULATE (
                        MAX ( 'Table'[Date.Time] ),
                        FILTER ( 'Table', 'Table'[Date.Time] &amp;lt; EARLIER ( 'Table'[Date.Time] ) )
                    )
            )
    )
RETURN
    SUMX (
        MyTable,
        IF ( [Previous Pump 1 RN] = 1, [Date.Time] - [Previous Date.Time] )
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;though this will return 14:00 for the data you give, not 13:57. I personally think this makes more sense (i.e. assuming the pump runs right up until the next 0); returning 13:57 would be a bit trickier.&lt;/P&gt;&lt;P&gt;This measure will respond to filters on the Date.Time field, e.g. filtering between&amp;nbsp;01/04/2020 04:00 and&amp;nbsp;01/04/2020 11:00 will produce a result of 07:00.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Sat, 28 Aug 2021 06:32:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-time-difference-between-specific-rows/m-p/2043796#M45900</guid>
      <dc:creator>Jos_Woolley</dc:creator>
      <dc:date>2021-08-28T06:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time difference between specific rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-time-difference-between-specific-rows/m-p/2051141#M46133</link>
      <description>&lt;P&gt;Hi Jos, thanks so much for taking the time to try and work on this. Unfortunately it doesn't seem to work, I have tried on my data and the sample data which I provided. For example, if I have no filters selected it will show 14:00 as you stated, however if I put a filter in (as per the below) it then shows 18:00 which isn't correct. I have it in the format of (hh:mm)&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>Wed, 01 Sep 2021 10:02:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-time-difference-between-specific-rows/m-p/2051141#M46133</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-09-01T10:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time difference between specific rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-time-difference-between-specific-rows/m-p/2051267#M46141</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Actually that result is perfectly correct for the filtering you've applied. A filter such as the one you've applied does not automatically include the entries in between the ones you've selected - it simply filters for those two dates.&lt;/P&gt;&lt;P&gt;I'll let you play about with other filter visuals and options (for example, sliders) until you've found the right one for you.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 11:31:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-time-difference-between-specific-rows/m-p/2051267#M46141</guid>
      <dc:creator>Jos_Woolley</dc:creator>
      <dc:date>2021-09-01T11:31:27Z</dc:date>
    </item>
  </channel>
</rss>

