<?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: Event Difference in Power Query</title>
    <link>https://community.fabric.microsoft.com/t5/Power-Query/Event-Difference/m-p/772296#M25852</link>
    <description>Can you add more details? The results on the data you provided were exactly the same you said you would expect.&lt;BR /&gt;&lt;BR /&gt;Tks</description>
    <pubDate>Wed, 21 Aug 2019 19:14:45 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-08-21T19:14:45Z</dc:date>
    <item>
      <title>Event Difference</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Event-Difference/m-p/771918#M25834</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I need to get the difference between every reopen and closed then return the same of the difference&lt;/P&gt;&lt;P&gt;1hr 2 mints + 29 mints + 2 mints = 1hr and 43 mints&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;AFFECTED OBJECT&lt;/TD&gt;&lt;TD&gt;LOG CREATION DATE&lt;/TD&gt;&lt;TD&gt;EVENT NAME&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10283&lt;/TD&gt;&lt;TD&gt;7/18/2019 12:20&lt;/TD&gt;&lt;TD&gt;reopenticket&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10283&lt;/TD&gt;&lt;TD&gt;7/18/2019 13:22&lt;/TD&gt;&lt;TD&gt;closeticket&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10283&lt;/TD&gt;&lt;TD&gt;7/18/2019 13:30&lt;/TD&gt;&lt;TD&gt;reopenticket&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10283&lt;/TD&gt;&lt;TD&gt;7/18/2019 13:59&lt;/TD&gt;&lt;TD&gt;closeticket&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10283&lt;/TD&gt;&lt;TD&gt;7/18/2019 15:26&lt;/TD&gt;&lt;TD&gt;reopenticket&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10283&lt;/TD&gt;&lt;TD&gt;7/18/2019 15:28&lt;/TD&gt;&lt;TD&gt;closeticket&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 13:10:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Event-Difference/m-p/771918#M25834</guid>
      <dc:creator>Matic20</dc:creator>
      <dc:date>2019-08-21T13:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Event Difference</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Event-Difference/m-p/772055#M25841</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please take a look at this code, I used the approach listed &lt;A href="https://community.powerbi.com/t5/Desktop/Power-Query-previous-row-value-based-on-criteria-O/td-p/125813" target="_self"&gt;here&amp;nbsp;&lt;/A&gt;to get the previous date, and then I added a custom column subtracting the times on each closedticket.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally, I grouped this on the affected object column to get the results you mentioned.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"AFFECTED OBJECT", Int64.Type}, {"LOG CREATION DATE", type text}, {"EVENT NAME", type text}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"LOG CREATION DATE", Order.Ascending}}),
    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Sorted Rows", {{"LOG CREATION DATE", type datetime}}, "en-US"),
    #"Sorted Rows1" = Table.Sort(#"Changed Type with Locale",{{"LOG CREATION DATE", Order.Ascending}}),
    #"Added Index" = Table.AddIndexColumn(#"Sorted Rows1", "Index", 1, 1),
    #"Added Index1" = Table.AddIndexColumn(#"Added Index", "Index.1", 0, 1),
    #"Merged Queries" = Table.NestedJoin(#"Added Index1",{"Index.1"},#"Added Index1",{"Index"},"Added Index1",JoinKind.LeftOuter),
    #"Expanded Added Index1" = Table.ExpandTableColumn(#"Merged Queries", "Added Index1", {"LOG CREATION DATE"}, {"LOG CREATION DATE.1"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Added Index1",{"Index", "Index.1"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"LOG CREATION DATE.1", "PREVIOUS LOG CREATION DATE"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Custom", each [PREVIOUS LOG CREATION DATE]-[LOG CREATION DATE]),
    #"Removed Columns1" = Table.RemoveColumns(#"Added Custom",{"Custom"}),
    #"Added Custom1" = Table.AddColumn(#"Removed Columns1", "Duration", each if [EVENT NAME] = "closeticket" then [LOG CREATION DATE]-[PREVIOUS LOG CREATION DATE] else null),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"Duration", type duration}}),
    #"Grouped Rows" = Table.Group(#"Changed Type1", {"AFFECTED OBJECT"}, {{"Total Duration", each List.Sum([Duration]), type duration}})
in
    #"Grouped Rows"&lt;/PRE&gt;&lt;P&gt;the final result is this.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please mark it as solution if that works for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Vagner&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 15:16:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Event-Difference/m-p/772055#M25841</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-08-21T15:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: Event Difference</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Event-Difference/m-p/772263#M25849</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;&amp;nbsp; I tried the proceedure provided but most of the results provided were wrong results&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 18:28:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Event-Difference/m-p/772263#M25849</guid>
      <dc:creator>Matic20</dc:creator>
      <dc:date>2019-08-21T18:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: Event Difference</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Event-Difference/m-p/772296#M25852</link>
      <description>Can you add more details? The results on the data you provided were exactly the same you said you would expect.&lt;BR /&gt;&lt;BR /&gt;Tks</description>
      <pubDate>Wed, 21 Aug 2019 19:14:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Event-Difference/m-p/772296#M25852</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-08-21T19:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Event Difference</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Event-Difference/m-p/778720#M26039</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="161507" data-lia-user-login="Matic20" class="lia-mention lia-mention-user"&gt;Matic20&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could create columns using DAX easier than in Power query.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;PRE&gt;index =
RANKX (
    FILTER (
        'Table (2)',
        'Table (2)'[AFFECTED OBJECT] = EARLIER ( 'Table (2)'[AFFECTED OBJECT] )
    ),
    [LOG CREATION DATE],
    ,
    ASC,
    DENSE
)


reopen time =
CALCULATE (
    SUM ( 'Table (2)'[LOG CREATION DATE] ),
    FILTER (
        ALLEXCEPT ( 'Table (2)', 'Table (2)'[AFFECTED OBJECT] ),
        'Table (2)'[index]
            = EARLIER ( 'Table (2)'[index] ) - 1
    )
)


time diff = IF([EVENT NAME]="closeticket",DATEDIFF([reopen time],[LOG CREATION DATE],SECOND))

total time per = CALCULATE(SUM('Table (2)'[time diff]),ALLEXCEPT('Table (2)','Table (2)'[AFFECTED OBJECT]))

final output =
VAR H =
    INT ( [total time per] / 3600 )
VAR M =
    INT ( ( [total time per] - INT ( [total time per] / 3600 ) * 3600 ) / 60 )
VAR S =
    MOD ( [total time per] - INT ( [total time per] / 3600 ) * 3600, 60 )
VAR hh =
    IF ( LEN ( H ) = 1, "0" &amp;amp; H, H )
VAR mm =
    IF ( LEN ( M ) = 1, "0" &amp;amp; M, M )
VAR ss =
    IF ( LEN ( S ) = 1, "0" &amp;amp; S, S )
RETURN
    hh &amp;amp; ":" &amp;amp; mm &amp;amp; ":" &amp;amp; ss
&lt;/PRE&gt;
&lt;P&gt;Best Regards&lt;BR /&gt;Maggie&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;Community Support Team _ Maggie Li&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;STRONG&gt;&lt;I&gt;Accept it as the solution&lt;/I&gt;&lt;/STRONG&gt; to help the other members find it more quickly.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 07:00:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Event-Difference/m-p/778720#M26039</guid>
      <dc:creator>v-juanli-msft</dc:creator>
      <dc:date>2019-08-29T07:00:46Z</dc:date>
    </item>
  </channel>
</rss>

