<?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: Performing Sum Calculation when Field values are combined in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423415#M167769</link>
    <description>&lt;P&gt;So for other services, if there are multiple records, you just want the max? What if there are multiple records for each of Service="FireTV" and Service="Echo", (say there are 2 entries for FireTV and 2 for Echo) in those cases should all those elapsedTime should be summed?&lt;/P&gt;</description>
    <pubDate>Wed, 22 Aug 2018 18:37:30 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2018-08-22T18:37:30Z</dc:date>
    <item>
      <title>Performing Sum Calculation when Field values are combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423406#M167760</link>
      <description>&lt;P&gt;Captured fields are Account, RequestorCode, Service, and ElapsedTime. An Account will have multiple RequestorCode, and a RequestorCode will have multiple Service. ElapsedTime format is "d.ddms". &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;I'm trying to combine data that have Service=FireTV and Service=Echo with &lt;STRONG&gt;Account&lt;/STRONG&gt; and &lt;STRONG&gt;RequestorCode&lt;/STRONG&gt; must be the field with identical data values. When combined, I need help to &lt;EM&gt;sum the ElapsedTime&lt;/EM&gt; between Service=FireTV and Service=Echo. There's only going to be a unique set of Service="FireTV" and Service="Echo" per Account + RequestorCode. &lt;/LI&gt;
&lt;LI&gt;After that, I need help to show &lt;EM&gt;the highest ElapsedTime&lt;/EM&gt; from each data that has the same &lt;STRONG&gt;Account&lt;/STRONG&gt; and &lt;STRONG&gt;RequestorCode&lt;/STRONG&gt;. &lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;&lt;STRONG&gt;Initial query&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=
| table _time Account RequestorCode Service ElapsedTime 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Sample event log&lt;/STRONG&gt; (Possibly populate multivalued fields)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2018-08-16 21:00:00,000 [-dd.dd.dd.ddd:dddd-d] [INFO] [                    ] [info:dd.dd.dd] (info.info.info) INFO   Rei21 - Service=Echo for Account=Rei, SiteID=555 ElapsedTime=20.0ms on RequestorCode=XX1 Channel=info OperatorID=Rei21 Page=info TransactionID=info
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Raw sample data&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Account: Rei
RequestorCode: XX1
Service: FireTV
ElapsedTime: 80.0ms    

Account : Rei
RequestorCode: XX1
Service: Echo
ElapsedTime: 20.0ms

Account : Rei
RequestorCode: XX1
Service: GoogleHome
ElapsedTime: 50.0ms

Account : Cliff
RequestorCode: XX1
Service: Google Home
ElapsedTime: 20.0ms

Account : Cliff
RequestorCode: XX1
Service: HomePod
ElapsedTime: 50.0ms

Account : Cliff
RequestorCode: XX2
Service: FireTV
ElapsedTime: 70.0ms
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Sample data when FireTV and Echo are combined as Amazon&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Account : Rei
RequestorCode: XX1
Service: Amazon
ElapsedTime: 100.0ms

Account : Rei
RequestorCode: XX1
Service: GoogleHome
ElapsedTime: 50.0ms

Account : Cliff
RequestorCode: XX1
Service: Google Home
ElapsedTime: 20.0ms

Account : Cliff
RequestorCode: XX1
Service: HomePod
ElapsedTime: 50.0ms

Account : Cliff
RequestorCode: XX2
Service: Amazon
ElapsedTime: 70.0ms
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Expected output&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Account: Rei
RequestorCode: XX1
Service: Amazon
ElapsedTime: 100.0ms

Account : Cliff
RequestorCode: XX1
Service: HomePod
ElapsedTime: 50.0ms

Account : Cliff
RequestorCode: XX2
Service: Amazon
ElapsedTime: 70.0ms
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Aug 2018 21:01:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423406#M167760</guid>
      <dc:creator>limalbert</dc:creator>
      <dc:date>2018-08-21T21:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: Performing Sum Calculation when Field values are combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423407#M167761</link>
      <description>&lt;P&gt;@limalbert,&lt;/P&gt;

&lt;P&gt;Try,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=yourindex "other search terms"
|table _time Service Account ElapsedTime RequestorCode
|stats sum(ElapsedTime) as totalElapsedTime,max(ElapsedTime) as highestElapsedTime  by Account,RequestorCode
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Aug 2018 03:15:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423407#M167761</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-08-22T03:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: Performing Sum Calculation when Field values are combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423408#M167762</link>
      <description>&lt;P&gt;Unfortunately, this won’t work for my case. If the data is simpler, this will work. But, there will be multiple data based on Account and RequestorCode. &lt;/P&gt;

&lt;P&gt;The elapsedTime from the service that needs to be combined has to be added together first. The, populate the highest elapsedTime based on the account and RequestorCode.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 03:34:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423408#M167762</guid>
      <dc:creator>limalbert</dc:creator>
      <dc:date>2018-08-22T03:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Performing Sum Calculation when Field values are combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423409#M167763</link>
      <description>&lt;P&gt;@limalbert your sample data and output in question do not match. Sum does not seem to be based on Account and RequestorCode. So for first example both are always 123 and XX1 for three sample data. So the final ElapsedTime should be 150. Even if you plan to take Service for correlation it will not be as per your expected output. Service Names do not match between Sample Data and Output. Please clarify.&lt;/P&gt;

&lt;P&gt;Also what is the requirement for highest elapsed time. Please explain with Sample Data again. If you do sum by Account and RequestorCode, then highest by same fields will not do anything unless you are changing the stats aggregating  field in the by clause. If you also want Service to be accounted for this you can add that to by clause in stats.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 04:07:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423409#M167763</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-08-22T04:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: Performing Sum Calculation when Field values are combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423410#M167764</link>
      <description>&lt;P&gt;Question is updated. Thank you for the feedback.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 04:24:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423410#M167764</guid>
      <dc:creator>limalbert</dc:creator>
      <dc:date>2018-08-22T04:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: Performing Sum Calculation when Field values are combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423411#M167765</link>
      <description>&lt;P&gt;Ok I move this to the comment section but do yo have sample data which reflects the scenario better?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 05:37:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423411#M167765</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-08-22T05:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: Performing Sum Calculation when Field values are combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423412#M167766</link>
      <description>&lt;P&gt;Sample data is updated in the question.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 12:15:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423412#M167766</guid>
      <dc:creator>limalbert</dc:creator>
      <dc:date>2018-08-22T12:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: Performing Sum Calculation when Field values are combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423413#M167767</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| table _time Acount RequestorCode Service ElapsedTime
| eval Service=if(Service="FireTV" OR Service="Echo","Amazon",Service)
| stats sum(ElapsedTime) as ElapsedTime by Acount RequestorCode Service
| eventstats max(ElapsedTime) as max by Account RequestorCode
| where ElapsedTime=max
| table Acount RequestorCode Service ElapsedTime
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Aug 2018 16:06:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423413#M167767</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-08-22T16:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Performing Sum Calculation when Field values are combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423414#M167768</link>
      <description>&lt;P&gt;This is close. Is it possible to add if statement for sum(ElapsedTime) only when Service=Amazon? Otherwise, keep the original ElapsedTime. This query is adding ElapsedTime for all the Services that's not Service=Amazon. &lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 17:45:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423414#M167768</guid>
      <dc:creator>limalbert</dc:creator>
      <dc:date>2018-08-22T17:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: Performing Sum Calculation when Field values are combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423415#M167769</link>
      <description>&lt;P&gt;So for other services, if there are multiple records, you just want the max? What if there are multiple records for each of Service="FireTV" and Service="Echo", (say there are 2 entries for FireTV and 2 for Echo) in those cases should all those elapsedTime should be summed?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 18:37:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423415#M167769</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-08-22T18:37:30Z</dc:date>
    </item>
    <item>
      <title>Re: Performing Sum Calculation when Field values are combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423416#M167770</link>
      <description>&lt;P&gt;You're correct! For other services, there are multiple records, and I want to get the max.&lt;/P&gt;

&lt;P&gt;For my case, there's only going to be a unique set of Service="FireTV" and Service="Echo" per Account + RequestorCode. Echo, FireTV, Google Home, and HomePod are used as a mock example.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 18:45:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423416#M167770</guid>
      <dc:creator>limalbert</dc:creator>
      <dc:date>2018-08-22T18:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Performing Sum Calculation when Field values are combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423417#M167771</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
 | table _time Acount RequestorCode Service ElapsedTime
 | eval Service=if(Service="FireTV" OR Service="Echo","Amazon",Service)
 | eventstats max(ElapsedTime) as max sum(eval(if(Service="Amazon",ElapsedTime,0))) as totalAmazon by Account RequestorCode
 | where ElapsedTime=max OR (Service="Amazon")
 | dedup Acount RequestorCode Service 
| eval ElapsedTime=if(totalAmazon&amp;gt;0,totalAmazon,ElapsedTime)
 | table Acount RequestorCode Service ElapsedTime
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Aug 2018 19:04:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423417#M167771</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-08-22T19:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: Performing Sum Calculation when Field values are combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423418#M167772</link>
      <description>&lt;P&gt;This works!! Thank you!&lt;BR /&gt;
Why do you use eventstats instead of stats for this problem? @somesoni2 &lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 20:06:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423418#M167772</guid>
      <dc:creator>limalbert</dc:creator>
      <dc:date>2018-08-22T20:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: Performing Sum Calculation when Field values are combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423419#M167773</link>
      <description>&lt;P&gt;The eventstats does the aggregation without changing the current resultset (it adds columns to existing results without reducing rows). This way all rows were intact and aggregation was done for rows with Service=Amazon. &lt;BR /&gt;
Prior to that, stats was doing aggregation for all, not only for Service=Amazon, so multiple values for a Account RequestorCode were getting collapsed into one.&lt;/P&gt;

&lt;P&gt;Also, After eventstats, there would be two rows for Service=Amazon (from original Service=FireTV and Service=Echo), so that dedup would remove one of them. The eventstats would've added sum(ElapsedTime) to both rows, so anyone will serve your purpose.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 21:24:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423419#M167773</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-08-22T21:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: Performing Sum Calculation when Field values are combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423420#M167774</link>
      <description>&lt;P&gt;@limalbert please do accept the answer if your query is resolved. Also do not forget to up vote the comments that helped! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Aug 2018 06:52:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-Sum-Calculation-when-Field-values-are-combined/m-p/423420#M167774</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-08-23T06:52:48Z</dc:date>
    </item>
  </channel>
</rss>

