<?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: sum function with conditions in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/sum-function-with-conditions/m-p/130205#M35451</link>
    <description>&lt;P&gt;Awesome!!! Thank you&lt;/P&gt;</description>
    <pubDate>Thu, 01 May 2014 16:26:43 GMT</pubDate>
    <dc:creator>Raghav2384</dc:creator>
    <dc:date>2014-05-01T16:26:43Z</dc:date>
    <item>
      <title>sum function with conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/sum-function-with-conditions/m-p/130201#M35447</link>
      <description>&lt;P&gt;Hey there,&lt;/P&gt;

&lt;P&gt;I am trying to get stats for one of our OpEx metrics&lt;/P&gt;

&lt;P&gt;Working query : &lt;CODE&gt;index=summary source="c:\\users\\njln0dr\\desktop\\splunk-use cases\\December.csv" |eval BTTR = Actual_Time_to_Resolve/3600|stats count(Number),sum(BTTR) as BTTR_Sum, perc95(BTTR) as P95 by "Group service"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;every event has Actual_Time_to_Resolve based on which,i calculate BTTR and then P95 which is the 95th percentile of all events BTTR. Now, i want to calculate&lt;BR /&gt;
P95 sum : sum of all the BTTRs which have a value greater than or equals to P95. Here's what i tried&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=summary source="c:\\users\\njln0dr\\desktop\\splunk-use cases\\December.csv" |eval BTTR = Actual_Time_to_Resolve/3600|stats count(Number),sum(BTTR) as BTTR_Sum, perc95(BTTR) as P95,sum(BTTR &amp;gt;= P95) as P95_Sum by "Group service"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I get the summary with all the evals but, P95_Sum is blank. Please help.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Raghav&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:22:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/sum-function-with-conditions/m-p/130201#M35447</guid>
      <dc:creator>Raghav2384</dc:creator>
      <dc:date>2020-09-28T16:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: sum function with conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/sum-function-with-conditions/m-p/130202#M35448</link>
      <description>&lt;P&gt;Hi Raghav2384,&lt;/P&gt;

&lt;P&gt;this will not work, because the &lt;CODE&gt;P95&lt;/CODE&gt; field is only available after your &lt;CODE&gt;stats&lt;/CODE&gt; not while it is running. This means you can use the &lt;CODE&gt;P95&lt;/CODE&gt; only in a next search command after the stats. &lt;/P&gt;

&lt;P&gt;Here you have a run everywhere example how it could be done:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal source=*metrics.log | stats count(series) as count, sum(kbps) as sum_kbps, perc95(kbps) as P95 by series | where sum_kbps &amp;gt;= P95 | stats  values(count) as count, sum(P95) as P95_sum by series, P95
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;adapt this to your needs and it should work....if your search looks something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=summary source="c:\\users\\njln0dr\\desktop\\splunk-use cases\\December.csv" | eval BTTR = Actual_Time_to_Resolve/3600 | stats count(Number) as Count, sum(BTTR) as BTTR_Sum, perc95(BTTR) as P95 by "Group service" | where BTTR &amp;gt;= P95 | stats values(Count) AS Count, values(BTTR_Sum) AS BTTR_Sum, sum(BTTR) as P95_Sum by "Group service"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;hope this helps to get you started ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Mon, 14 Apr 2014 07:01:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/sum-function-with-conditions/m-p/130202#M35448</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-04-14T07:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: sum function with conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/sum-function-with-conditions/m-p/130203#M35449</link>
      <description>&lt;P&gt;Hey MuS,&lt;BR /&gt;
I tried as you suggested but i get an error.Nothing moves forward after pipe |where &lt;BR /&gt;
Error: Error in 'where' command: The 'sum' function is unsupported or undefined.&lt;BR /&gt;
Here's the query i tried after your suggestion, &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=summary source="c:\\users\\njln0dr\\desktop\\splunk-use cases\\December.csv" | eval BTTR = Actual_Time_to_Resolve/3600 |stats count(Number) as Count, sum(BTTR) as BTTR_Sum, perc95(BTTR) as P95 by "Group service"|where sum(BTTR) &amp;gt;= P95 | stats values(Count) as Count,values(BTTR_Sum) as BTTR_Sum,values(P95) as P95,sum(BTTR) as P95_Sum by "Group service"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Thanks,Rag&lt;/P&gt;</description>
      <pubDate>Mon, 14 Apr 2014 23:04:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/sum-function-with-conditions/m-p/130203#M35449</guid>
      <dc:creator>Raghav2384</dc:creator>
      <dc:date>2014-04-14T23:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: sum function with conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/sum-function-with-conditions/m-p/130204#M35450</link>
      <description>&lt;P&gt;try this:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=summary source="c:\\users\\njln0dr\\desktop\\splunk-use cases\\December.csv" | eval BTTR = Actual_Time_to_Resolve/3600 | stats count(Number) as Count, sum(BTTR) as BTTR_Sum, perc95(BTTR) as P95 by "Group service" | where BTTR_Sum &amp;gt;= P95 | stats values(Count) as Count,values(BTTR_Sum) as BTTR_Sum,values(P95) as P95,sum(BTTR) as P95_Sum by "Group service"&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;use the &lt;CODE&gt;BTTR_sum&lt;/CODE&gt; name in &lt;CODE&gt;where&lt;/CODE&gt; and not the &lt;CODE&gt;sum()&lt;/CODE&gt; function. the sum name was created by the stats command and contains the summary of the BTTR values.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2014 05:41:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/sum-function-with-conditions/m-p/130204#M35450</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-04-15T05:41:05Z</dc:date>
    </item>
    <item>
      <title>Re: sum function with conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/sum-function-with-conditions/m-p/130205#M35451</link>
      <description>&lt;P&gt;Awesome!!! Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 01 May 2014 16:26:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/sum-function-with-conditions/m-p/130205#M35451</guid>
      <dc:creator>Raghav2384</dc:creator>
      <dc:date>2014-05-01T16:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: sum function with conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/sum-function-with-conditions/m-p/130206#M35452</link>
      <description>&lt;P&gt;Feel free to accept this answer by ticking the tick, thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 01 May 2014 17:41:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/sum-function-with-conditions/m-p/130206#M35452</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-05-01T17:41:37Z</dc:date>
    </item>
  </channel>
</rss>

