<?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: Mathematical calculations on rows based on grouping in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/366000#M107958</link>
    <description>&lt;P&gt;Thanks TISKAR for your time on this.&lt;BR /&gt;
I have commented on Somesoni2's post the missing piece. Can you please revisit this and try to answer.&lt;/P&gt;</description>
    <pubDate>Thu, 26 Apr 2018 22:56:47 GMT</pubDate>
    <dc:creator>imran1386</dc:creator>
    <dc:date>2018-04-26T22:56:47Z</dc:date>
    <item>
      <title>Mathematical calculations on rows based on grouping</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/365996#M107954</link>
      <description>&lt;P&gt;This is my table that I have extracted with the help of this query:&lt;/P&gt;

&lt;P&gt;index=auto_adv_txn_preprod  source=&lt;EM&gt;cap&lt;/EM&gt; ( &lt;EM&gt;alfaws&lt;/EM&gt; OR &lt;EM&gt;IODS*DAOImpl&lt;/EM&gt; OR &lt;EM&gt;prism&lt;/EM&gt; OR &lt;EM&gt;service-&lt;/EM&gt; ) &lt;EM&gt;ADV_AAOSF07&lt;/EM&gt;&lt;BR /&gt;
            | rex "^(?:[^ \n]* ){3}(?P&lt;TID&gt;[^ ]+)(?:[^ \n]* ){5}(?P&lt;SERVICECALL&gt;[^ ]+)(?:[^ \n]* ){7}(?P&lt;HTTPSTATUS&gt;\d+)\s+-\s+(?P&lt;RESTIME&gt;\d+)" &lt;BR /&gt;
            | eval ServiceCall1 = replace(ServiceCall, "/\d+,*","/{id}")&lt;BR /&gt;
            | eval ServiceCall = mvindex(split(ServiceCall1, ";"),0)&lt;BR /&gt;
            | eval Functionality = replace(TID, "_\d+","")&lt;BR /&gt;
            | table TID, ServiceCall, Functionality, ResTime&lt;/RESTIME&gt;&lt;/HTTPSTATUS&gt;&lt;/SERVICECALL&gt;&lt;/TID&gt;&lt;/P&gt;

&lt;P&gt;Here is the initial Output :&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/248577-capture1.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;This is the Output I am expecting:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/248578-capture2.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;The Time Difference Column will have the Time difference of URLType1 with Sum of all other URLTypes for any particular TID and Functionality. Any kind of help is appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:16:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/365996#M107954</guid>
      <dc:creator>imran1386</dc:creator>
      <dc:date>2020-09-29T19:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: Mathematical calculations on rows based on grouping</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/365997#M107955</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your current search giving fields TID Functionality URL Time
| eval Time1=if(URL="URLType1",Time,0)
| eval Time2=if(URL!="URLType1",Time,0)
| eval URL="URLType1"
| stats sum(Time1) as Time1 sum(Time2) as Time2 by Functionality URL
| eval Time=Time1-Time2 | table Functionality URL Time
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Apr 2018 20:45:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/365997#M107955</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-04-26T20:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Mathematical calculations on rows based on grouping</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/365998#M107956</link>
      <description>&lt;P&gt;@imran1386, can you try this please:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval URL="URLType1"| stats sum(Time) as somme max(Time) as max by Functionality URL | eval Time=2*max-somme | table Functionality URL Time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I test it, it work for me&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 21:33:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/365998#M107956</guid>
      <dc:creator>TISKAR</dc:creator>
      <dc:date>2018-04-26T21:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Mathematical calculations on rows based on grouping</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/365999#M107957</link>
      <description>&lt;P&gt;Thanks Somesoni2 for quick response.&lt;BR /&gt;
The problem is "URLType1" is dynamics value and is the primary value from which rest of the URLs associated with the same TID(Unique Transaction ID) will be subtracted for any given functionality.&lt;/P&gt;

&lt;P&gt;I have 40-50 different functionalities and each has different "URLType1" values.&lt;/P&gt;

&lt;P&gt;The reason I have to calculate Time difference based off TID is because at the very end I need to calculate 90percentile grouped by functionality.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 22:51:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/365999#M107957</guid>
      <dc:creator>imran1386</dc:creator>
      <dc:date>2018-04-26T22:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: Mathematical calculations on rows based on grouping</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/366000#M107958</link>
      <description>&lt;P&gt;Thanks TISKAR for your time on this.&lt;BR /&gt;
I have commented on Somesoni2's post the missing piece. Can you please revisit this and try to answer.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 22:56:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/366000#M107958</guid>
      <dc:creator>imran1386</dc:creator>
      <dc:date>2018-04-26T22:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: Mathematical calculations on rows based on grouping</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/366001#M107959</link>
      <description>&lt;P&gt;@imran1386, can you try this please:&lt;/P&gt;

&lt;P&gt;if URLType1 take always the first position:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;YourBaseSearch&amp;gt; | streamstats count by Functionality | eval URL=if(count=1,URL,null) | filldown URL | stats sum(Time) as somme max(Time) as max by Functionality URL | eval Time=2*max-somme | table Functionality URL Time 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;if URLType1 have always the max value of Time Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;YourBaseSearch&amp;gt;| eventstats max(Time) as max by Functionality | eval URL=if(max=Time,URL,null) | filldown URL| stats sum(Time) as somme max(Time) as max by Functionality URL | eval Time=2*max-somme | table Functionality URL Time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Happy Splunking&lt;/P&gt;</description>
      <pubDate>Fri, 27 Apr 2018 08:51:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/366001#M107959</guid>
      <dc:creator>TISKAR</dc:creator>
      <dc:date>2018-04-27T08:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: Mathematical calculations on rows based on grouping</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/366002#M107960</link>
      <description>&lt;P&gt;That doesn't change the conceptual solution, you then just need to come up with a different condition for the if statements on lines 2 and 3 of @somesoni2's solution.&lt;/P&gt;

&lt;P&gt;And if you want any help with that, you'll have to provide more insight into what those URL values are and how to find the 'URLType1'.&lt;/P&gt;

&lt;P&gt;Alternatively, if the Time for 'URLType1' is always the sum of the others + something extra. You could filter by finding the largest time:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your current search giving fields TID Functionality URL Time
 | eventstats max(Time) as max_time by Functionality
 | eval Time1=if(Time=max_time,Time,0)
 | eval Time2=if(Time!=max_time,Time,0)
 | eval URL="URLType1"
 | stats sum(Time1) as Time1 sum(Time2) as Time2 by Functionality URL
 | eval Time=Time1-Time2 
 | table Functionality URL Time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the URLType1 is always the first url type that comes in chronologically, then the solution using &lt;CODE&gt;streamstats count...&lt;/CODE&gt; from @TISKAR would be a better alternative.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Apr 2018 09:18:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/366002#M107960</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-04-27T09:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Mathematical calculations on rows based on grouping</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/366003#M107961</link>
      <description>&lt;P&gt;@imran1386, I add the answer, can you test it please&lt;/P&gt;</description>
      <pubDate>Fri, 27 Apr 2018 10:11:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/366003#M107961</guid>
      <dc:creator>TISKAR</dc:creator>
      <dc:date>2018-04-27T10:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: Mathematical calculations on rows based on grouping</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/366004#M107962</link>
      <description>&lt;P&gt;Your dynamic nature of URL field can be handled by making an assumption that your base search gives the "URLType1" as first value in the event, like your sample data is showing. If that can be assumed try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your current search giving fields TID Functionality URL Time
| streamstats count as sno by TID Functionality
 | eval Time1=if(sno=1,Time,0)
 | eval Time2=if(sno&amp;gt;1,Time,0)
 | stats sum(Time1) as Time1 sum(Time2) as Time2 first(URL) as URL by Functionality
 | eval Time=Time1-Time2 | table Functionality URL Time
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Apr 2018 14:47:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Mathematical-calculations-on-rows-based-on-grouping/m-p/366004#M107962</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-04-27T14:47:08Z</dc:date>
    </item>
  </channel>
</rss>

