<?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 calculate the duration between row and previous row (for same user) in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2393095#M62315</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;I’m relatively new to DAX and got stuck.&lt;/P&gt;&lt;P&gt;I’m trying to get a measure (or column) in place that calculates the amount of time between the activity of a consumer and his/her previous activity (duration).&lt;BR /&gt;&lt;img /&gt;&lt;BR /&gt;Ideally I would have a column (or measure) that gives the duration for a specific id. Where the duration is the time for the specific consumer on that line and the most recent timestamp available for that consumer before this one. For the first yellow entry (consumer 190275) that would mean 1.41.23-1.40.56 0.27 seconds.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Originally I built a unique ranking column per Consumer for all timestamps available, which is working, but even with that in place I get stuck:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Here is my latest but clearly not successful:&lt;BR /&gt;Duration =&lt;BR /&gt;//timestamp current (TC) - timestamp previous (TP)&lt;BR /&gt;VAR PreviousRank = [Ranking]+1)&lt;BR /&gt;VAR TC = [Date_time]&lt;BR /&gt;VAR Cid = [ConsumerID]&lt;BR /&gt;VAR TP = LOOKUPVALUE([Date_time],[Ranking],PreviousRank) // issue is that this is not filtered on specific consumer&lt;BR /&gt;return&lt;BR /&gt;FILter(table,[consumerid]=Cid &amp;amp;&amp;amp; [Ranking] = PreviousRank&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Any sug&lt;SPAN&gt;gestions how to address this?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 14 Mar 2022 16:28:34 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-03-14T16:28:34Z</dc:date>
    <item>
      <title>calculate the duration between row and previous row (for same user)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2393095#M62315</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;I’m relatively new to DAX and got stuck.&lt;/P&gt;&lt;P&gt;I’m trying to get a measure (or column) in place that calculates the amount of time between the activity of a consumer and his/her previous activity (duration).&lt;BR /&gt;&lt;img /&gt;&lt;BR /&gt;Ideally I would have a column (or measure) that gives the duration for a specific id. Where the duration is the time for the specific consumer on that line and the most recent timestamp available for that consumer before this one. For the first yellow entry (consumer 190275) that would mean 1.41.23-1.40.56 0.27 seconds.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Originally I built a unique ranking column per Consumer for all timestamps available, which is working, but even with that in place I get stuck:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Here is my latest but clearly not successful:&lt;BR /&gt;Duration =&lt;BR /&gt;//timestamp current (TC) - timestamp previous (TP)&lt;BR /&gt;VAR PreviousRank = [Ranking]+1)&lt;BR /&gt;VAR TC = [Date_time]&lt;BR /&gt;VAR Cid = [ConsumerID]&lt;BR /&gt;VAR TP = LOOKUPVALUE([Date_time],[Ranking],PreviousRank) // issue is that this is not filtered on specific consumer&lt;BR /&gt;return&lt;BR /&gt;FILter(table,[consumerid]=Cid &amp;amp;&amp;amp; [Ranking] = PreviousRank&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Any sug&lt;SPAN&gt;gestions how to address this?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 16:28:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2393095#M62315</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-14T16:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the duration between row and previous row (for same user)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2393195#M62322</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So for the same ID, the first record is the start of the first activity and the 2nd record is the end of the fist activity. The 3rd record would be the start of the 2nd activity and the 4th record is the end of the 2nd activity. Is that correct? The activity does not have to start and end in the same day. It can start right before midnight and end right after midnight. Am I right?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 17:09:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2393195#M62322</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-03-14T17:09:29Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the duration between row and previous row (for same user)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2393360#M62332</link>
      <description>&lt;P&gt;Thanks for asking:&lt;BR /&gt;It's about how long it takes before somebody comes back.&lt;BR /&gt;You work backwards in time so the order *per consumerid* is&lt;BR /&gt;- latest&lt;BR /&gt;- latest -1&lt;BR /&gt;-latest -2 etc.&lt;BR /&gt;The duration for latest -1 is the time between latest and latest-1 (duration latest -1 ends when latest starts).&lt;BR /&gt;The duration for latest -2 is the time between latest-1 and latest-2.&lt;BR /&gt;The duration for latest -3 is the time between latest-2 and latest-3&lt;BR /&gt;&lt;BR /&gt;Hope this answers,&lt;BR /&gt;KR Kees&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 18:30:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2393360#M62332</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-14T18:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the duration between row and previous row (for same user)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2393451#M62340</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this will work&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Duration =
VAR CurrentDateTime = 'Table'[End_Date_Time]
VAR T1 =
    CALCULATETABLE (
        'Table',
        ALLEXCEPT ( 'Table', 'Table'[CustomerID], 'Table'[VariableID] )
    )
VAR T2 =
    FILTER ( T1, [End_Date_Time] &amp;lt; CurrentDateTime )
VAR T3 =
    TOPN ( 1, T2, [End_Date_Time], ASC )
VAR NextDateTime =
    SELECTCOLUMNS ( T3, @DateTime, [End_Date_Time] )
RETURN
    IF ( NOT ISBLANK ( NextDateTime ), CurrentDateTime - NextDateTime )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 19:50:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2393451#M62340</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-03-14T19:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the duration between row and previous row (for same user)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2394212#M62396</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;I create a column with your suggested code (although also tried as measure).&lt;BR /&gt;It runs into an issue with the&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;SELECTCOLUMNS ( T3, @DateTime, [End_Date_Time] )&lt;/PRE&gt;&lt;P&gt;even if I change the&amp;nbsp;@DateTime to @currentDateTime it gives an message that:&lt;BR /&gt;&lt;EM&gt;The 'CurrentDateTime'parameter could not be resolved because it was referenced in an inner subexpression.&lt;BR /&gt;&lt;/EM&gt;Is there a way arround this?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 06:58:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2394212#M62396</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-15T06:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the duration between row and previous row (for same user)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2394244#M62397</link>
      <description>&lt;P&gt;Anonymous&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Thank you for your reply. Can you please share some sample (dummy) data so I can try from my side?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 07:07:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2394244#M62397</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-03-15T07:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the duration between row and previous row (for same user)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2394409#M62408</link>
      <description>&lt;P&gt;HI&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;It could be the name of the vaiable&lt;BR /&gt;Try&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Duration =
VAR Current_DateTime = 'Table'[End_Date_Time]
VAR T1 =
    CALCULATETABLE (
        'Table',
        ALLEXCEPT ( 'Table', 'Table'[CustomerID], 'Table'[VariableID] )
    )
VAR T2 =
    FILTER ( T1, [End_Date_Time] &amp;lt; Current_DateTime )
VAR T3 =
    TOPN ( 1, T2, [End_Date_Time], ASC )
VAR NextDateTime =
    SELECTCOLUMNS ( T3, @DateTime, [End_Date_Time] )
RETURN
    IF ( NOT ISBLANK ( NextDateTime ), Current_DateTime - NextDateTime )&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 15 Mar 2022 07:58:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2394409#M62408</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-03-15T07:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the duration between row and previous row (for same user)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2395817#M62501</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;I truly appreciate your help here.&amp;nbsp;&lt;BR /&gt;Attaching CSV or XLSX did not work so here is a table:&lt;BR /&gt;&lt;BR /&gt;id ConsumerID Date_time&lt;BR /&gt;229772 116363 3/14/2022 8:02&lt;BR /&gt;229773 145910 3/14/2022 8:33&lt;BR /&gt;229817 145910 3/14/2022 8:57&lt;BR /&gt;229820 189803 3/14/2022 10:15&lt;BR /&gt;229821 190130 3/14/2022 10:19&lt;BR /&gt;229768 190174 3/14/2022 7:22&lt;BR /&gt;229769 190177 3/14/2022 7:43&lt;BR /&gt;229770 190177 3/14/2022 7:44&lt;BR /&gt;229771 190177 3/14/2022 7:44&lt;BR /&gt;229774 190186 3/14/2022 8:38&lt;BR /&gt;229775 190186 3/14/2022 8:38&lt;BR /&gt;229776 190186 3/14/2022 8:38&lt;BR /&gt;229777 190186 3/14/2022 8:39&lt;BR /&gt;229778 190186 3/14/2022 8:39&lt;BR /&gt;229779 190187 3/14/2022 8:40&lt;BR /&gt;229819 190217 3/14/2022 10:03&lt;BR /&gt;229818 190218 3/14/2022 10:02&lt;BR /&gt;229823 190241 3/14/2022 11:40&lt;BR /&gt;229824 190241 3/14/2022 11:44&lt;BR /&gt;229825 190244 3/14/2022 11:45&lt;BR /&gt;229826 190244 3/14/2022 12:01&lt;BR /&gt;229827 190253 3/14/2022 12:25&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please keep in mind that the previous ConsumerID activity can be much lower in the table.&lt;BR /&gt;So, how do I add a table (that gives me per (unique) ID the amount of time between this entry and the previous entry for the same ConsumerID?&lt;BR /&gt;&lt;BR /&gt;Also with the last suggestion I run into same error message.&lt;BR /&gt;Worstkees&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 15:51:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2395817#M62501</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-15T15:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the duration between row and previous row (for same user)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2397119#M62584</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp; sorry, small correction between **'s :&lt;BR /&gt;&lt;SPAN&gt;So, how do I add a *column* (that gives me per (unique) ID the amount of time between this entry and the previous entry for the same ConsumerID?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 07:44:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2397119#M62584</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-16T07:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the duration between row and previous row (for same user)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2397226#M62594</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;BR /&gt;Here is the sample file with the solution&amp;nbsp;&lt;A href="https://www.dropbox.com/t/HdxeyDA84DyTOzJq" target="_blank"&gt;https://www.dropbox.com/t/HdxeyDA84DyTOzJq&lt;/A&gt;&lt;BR /&gt;This is the code of the calculated column.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;Duration = 
VAR Current_DateTime = 'Table'[Date_Time]
VAR T1 =
    CALCULATETABLE (
        'Table',
        ALLEXCEPT ( 'Table', 'Table'[ConsumerID] )
    )
VAR T2 =
    FILTER ( T1, [Date_Time] &amp;lt; Current_DateTime )
VAR T3 =
    TOPN ( 1, T2, [Date_Time], DESC )
VAR NextDateTime =
    SELECTCOLUMNS ( T3, "@DateTime", [Date_Time] )
VAR Result =
    IF ( NOT ISBLANK ( NextDateTime ), Current_DateTime - NextDateTime )
RETURN
    Result&lt;/LI-CODE&gt;&lt;P&gt;Please let me know if this is the result that you desire.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 08:25:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2397226#M62594</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-03-16T08:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the duration between row and previous row (for same user)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2399053#M62699</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp;Not sure what the superlative is for brilliant, perhaps TamarJ1! Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 21:13:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-the-duration-between-row-and-previous-row-for-same/m-p/2399053#M62699</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-16T21:13:39Z</dc:date>
    </item>
  </channel>
</rss>

