<?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 How to run comparison after a group by? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-comparison-after-a-group-by/m-p/613291#M213141</link>
    <description>&lt;P&gt;I am running a query where I'm trying to calculate the difference between the start and end times a request travels through a service (aka latency). In order to achieve this I search for two logs: one for the start, one for the end, I then subtract the start and end times, and finally do a group by&amp;nbsp;X_Request_ID-which is unique per request. What I have at this point is:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-09-15 at 6.28.02 PM.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/21491i86400DCBB5E01AC0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2022-09-15 at 6.28.02 PM.png" alt="Screen Shot 2022-09-15 at 6.28.02 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;What I want to do now is to only display the count of all requests that took over 1 second.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My attempt at this looks like:&lt;/P&gt;&lt;P&gt;index=prod component="card-notification-service" eventCategory=transactions eventType=auth AND ("is going to process" OR ("to POST &lt;A href="https://apay-partner-api.apple.com/ccs/v1/users/eventNotification/transactions/auth" target="_blank" rel="noopener"&gt;https://apay-partner-api.apple.com/ccs/v1/users/eventNotification/transactions/auth&lt;/A&gt;" AND status=204))&lt;/P&gt;&lt;P&gt;| eval diff=if(searchmatch("is going to process"), _time*-1, 0)&lt;/P&gt;&lt;P&gt;| eval Start=if(searchmatch("is going to process"), _time, NULL)&lt;/P&gt;&lt;P&gt;| eval diff=if(searchmatch("to POST &lt;A href="https://apay-partner-api.apple.com/ccs/v1/users/eventNotification/transactions/auth" target="_blank" rel="noopener"&gt;https://app.transactions/auth&lt;/A&gt;"), diff+_time, diff)&lt;/P&gt;&lt;P&gt;| eval End=if(searchmatch("to POST &lt;A href="https://apay-partner-api.apple.com/ccs/v1/users/eventNotification/transactions/auth" target="_blank" rel="noopener"&gt;https://app.transactions/auth&lt;/A&gt;"), _time, NULL) | eval seriesName="Baxter&amp;lt;-&amp;gt;Saturn&lt;/P&gt;&lt;P&gt;| streamstats sum(diff) by X_Request_ID as FinalDiff |&lt;STRONG&gt;where FinalDiff&amp;gt; 1.0&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;| timechart span=5m partial=f count by seriesName&lt;/P&gt;&lt;P&gt;I’ve gotten everything to compile fine before the bolded where clause above. I suspect it’s because in the streamstats command prior, the “as” is only naming the query and not persisting the grouping of the query. Regardless this leads me to the question I am trying to solve: How can I persist sum(diff) after grouping it by X_Request_ID so that in the next pipe I can perform a comparison in the where operation?&lt;/P&gt;</description>
    <pubDate>Thu, 15 Sep 2022 17:38:00 GMT</pubDate>
    <dc:creator>kimsej</dc:creator>
    <dc:date>2022-09-15T17:38:00Z</dc:date>
    <item>
      <title>How to run comparison after a group by?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-comparison-after-a-group-by/m-p/613291#M213141</link>
      <description>&lt;P&gt;I am running a query where I'm trying to calculate the difference between the start and end times a request travels through a service (aka latency). In order to achieve this I search for two logs: one for the start, one for the end, I then subtract the start and end times, and finally do a group by&amp;nbsp;X_Request_ID-which is unique per request. What I have at this point is:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-09-15 at 6.28.02 PM.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/21491i86400DCBB5E01AC0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2022-09-15 at 6.28.02 PM.png" alt="Screen Shot 2022-09-15 at 6.28.02 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;What I want to do now is to only display the count of all requests that took over 1 second.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My attempt at this looks like:&lt;/P&gt;&lt;P&gt;index=prod component="card-notification-service" eventCategory=transactions eventType=auth AND ("is going to process" OR ("to POST &lt;A href="https://apay-partner-api.apple.com/ccs/v1/users/eventNotification/transactions/auth" target="_blank" rel="noopener"&gt;https://apay-partner-api.apple.com/ccs/v1/users/eventNotification/transactions/auth&lt;/A&gt;" AND status=204))&lt;/P&gt;&lt;P&gt;| eval diff=if(searchmatch("is going to process"), _time*-1, 0)&lt;/P&gt;&lt;P&gt;| eval Start=if(searchmatch("is going to process"), _time, NULL)&lt;/P&gt;&lt;P&gt;| eval diff=if(searchmatch("to POST &lt;A href="https://apay-partner-api.apple.com/ccs/v1/users/eventNotification/transactions/auth" target="_blank" rel="noopener"&gt;https://app.transactions/auth&lt;/A&gt;"), diff+_time, diff)&lt;/P&gt;&lt;P&gt;| eval End=if(searchmatch("to POST &lt;A href="https://apay-partner-api.apple.com/ccs/v1/users/eventNotification/transactions/auth" target="_blank" rel="noopener"&gt;https://app.transactions/auth&lt;/A&gt;"), _time, NULL) | eval seriesName="Baxter&amp;lt;-&amp;gt;Saturn&lt;/P&gt;&lt;P&gt;| streamstats sum(diff) by X_Request_ID as FinalDiff |&lt;STRONG&gt;where FinalDiff&amp;gt; 1.0&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;| timechart span=5m partial=f count by seriesName&lt;/P&gt;&lt;P&gt;I’ve gotten everything to compile fine before the bolded where clause above. I suspect it’s because in the streamstats command prior, the “as” is only naming the query and not persisting the grouping of the query. Regardless this leads me to the question I am trying to solve: How can I persist sum(diff) after grouping it by X_Request_ID so that in the next pipe I can perform a comparison in the where operation?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 17:38:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-comparison-after-a-group-by/m-p/613291#M213141</guid>
      <dc:creator>kimsej</dc:creator>
      <dc:date>2022-09-15T17:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to run comparison after a group by?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-comparison-after-a-group-by/m-p/613296#M213145</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Switch up the order of things a bit, and this should work for you:&lt;BR /&gt;&lt;BR /&gt;| streamstats &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;sum(diff) as FinalDiff&lt;/STRONG&gt; &lt;/FONT&gt;by X_Request_ID |&lt;/SPAN&gt;where FinalDiff&amp;gt; 1.0&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 18:01:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-comparison-after-a-group-by/m-p/613296#M213145</guid>
      <dc:creator>thesplunkmonkey</dc:creator>
      <dc:date>2022-09-15T18:01:23Z</dc:date>
    </item>
  </channel>
</rss>

