<?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 calculate difference between two rows of a table if another field on row is same for both? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-two-rows-of-a-table-if/m-p/500364#M139312</link>
    <description>&lt;P&gt;Hello Everyone,&lt;BR /&gt;
I have a table like this:&lt;BR /&gt;
&lt;STRONG&gt;DVN&lt;/STRONG&gt;.  &lt;STRONG&gt;Region&lt;/STRONG&gt;  &lt;STRONG&gt;Name&lt;/STRONG&gt;     &lt;STRONG&gt;Count&lt;/STRONG&gt;&lt;BR /&gt;
201            SAM               Shapes              20010&lt;BR /&gt;
201            SAM               Points               24218&lt;BR /&gt;
202            SAM               Shapes             20102&lt;BR /&gt;
202            SAM              Points                23231&lt;/P&gt;

&lt;P&gt;I want to calculate difference between count values for rows whose Name is same but DVN is different. For ex.-- For Shapes name, difference between 3rd row and 1st row should be taken.&lt;/P&gt;

&lt;P&gt;My existing query to show this table looks like this: &lt;BR /&gt;
index=**&lt;EM&gt;| rex field=_raw "{.&lt;/EM&gt;?(?{(.&lt;EM&gt;?})).&lt;/EM&gt;}" | eval trimVal = trim(replace(ps, "\\", "")) | spath input=trimVal | where region=$region$ | where inputFeatureName="Shapes" OR inputFeatureName ="Points"| rename partitionName AS PartitionName, inputFeatureName AS FeatureName, inputFeatureCount AS FeatureCount, dvn AS DVN, region AS Region| where isnotnull(PartitionName)  | table PartitionName,DVN,Region, FeatureName, FeatureCount | stats sum(FeatureCount) as Count by DVN,Region,FeatureName | sort Region&lt;/P&gt;

&lt;P&gt;Any help is appreciated,&lt;BR /&gt;
Thanks&lt;/P&gt;</description>
    <pubDate>Mon, 18 May 2020 09:36:00 GMT</pubDate>
    <dc:creator>pulkit1997</dc:creator>
    <dc:date>2020-05-18T09:36:00Z</dc:date>
    <item>
      <title>How to calculate difference between two rows of a table if another field on row is same for both?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-two-rows-of-a-table-if/m-p/500364#M139312</link>
      <description>&lt;P&gt;Hello Everyone,&lt;BR /&gt;
I have a table like this:&lt;BR /&gt;
&lt;STRONG&gt;DVN&lt;/STRONG&gt;.  &lt;STRONG&gt;Region&lt;/STRONG&gt;  &lt;STRONG&gt;Name&lt;/STRONG&gt;     &lt;STRONG&gt;Count&lt;/STRONG&gt;&lt;BR /&gt;
201            SAM               Shapes              20010&lt;BR /&gt;
201            SAM               Points               24218&lt;BR /&gt;
202            SAM               Shapes             20102&lt;BR /&gt;
202            SAM              Points                23231&lt;/P&gt;

&lt;P&gt;I want to calculate difference between count values for rows whose Name is same but DVN is different. For ex.-- For Shapes name, difference between 3rd row and 1st row should be taken.&lt;/P&gt;

&lt;P&gt;My existing query to show this table looks like this: &lt;BR /&gt;
index=**&lt;EM&gt;| rex field=_raw "{.&lt;/EM&gt;?(?{(.&lt;EM&gt;?})).&lt;/EM&gt;}" | eval trimVal = trim(replace(ps, "\\", "")) | spath input=trimVal | where region=$region$ | where inputFeatureName="Shapes" OR inputFeatureName ="Points"| rename partitionName AS PartitionName, inputFeatureName AS FeatureName, inputFeatureCount AS FeatureCount, dvn AS DVN, region AS Region| where isnotnull(PartitionName)  | table PartitionName,DVN,Region, FeatureName, FeatureCount | stats sum(FeatureCount) as Count by DVN,Region,FeatureName | sort Region&lt;/P&gt;

&lt;P&gt;Any help is appreciated,&lt;BR /&gt;
Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 09:36:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-two-rows-of-a-table-if/m-p/500364#M139312</guid>
      <dc:creator>pulkit1997</dc:creator>
      <dc:date>2020-05-18T09:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate difference between two rows of a table if another field on row is same for both?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-two-rows-of-a-table-if/m-p/500365#M139313</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval DVN="201",Region="SAM",Name="Shapes",Count="20010" 
| append 
    [| makeresults 
    | eval DVN="201",Region="SAM",Name="Points",Count="24218"] 
| append 
    [| makeresults 
    | eval DVN="202",Region="SAM",Name="Shapes",Count="20102"] 
| append 
    [| makeresults 
    | eval DVN="202",Region="SAM",Name="Points",Count="23231"] 
| table DVN, Region, Name, Count 
| stats dc(DVN) as dc_DVN values(*) as * by Name 
| search dc_DVN&amp;gt;1
| eval count1=mvindex(Count,0), count2=mvindex(Count,1), diff=abs('count1'-'count2')
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Everything before the table command, was just to give me the same result set to work with as you . Then I merged the results that shared a name and took a distinct count of DVN so I could eliminate results that weren't duplicates (although there weren't any in this data set). My search dc_DVN&amp;gt;1 eliminates items that don't have multiple DVNs.&lt;/P&gt;

&lt;P&gt;Then my evals were just for doing the math to find the difference. Hopefully this works for your use case or gives you a good starting point!&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 14:42:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-two-rows-of-a-table-if/m-p/500365#M139313</guid>
      <dc:creator>acfecondo75</dc:creator>
      <dc:date>2020-05-18T14:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate difference between two rows of a table if another field on row is same for both?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-two-rows-of-a-table-if/m-p/500366#M139314</link>
      <description>&lt;P&gt;Thanks for your response!!&lt;BR /&gt;
My search query will not return any kind of duplicates, be it DVN or Name. So no worry about duplicates. The eval function is not working for my case because I will &lt;/P&gt;

&lt;P&gt;For my use case, I need to calculate degradation in Count for a particular Name and region. This degradation difference will be between  count of  latest DVN and the DVN before it  for a particular Name and region.&lt;BR /&gt;
And I am having multiple regions and two Names only. So I need to do this for every region.&lt;BR /&gt;
For Ex. For region= "SAM" and Name="Points", I need to calculate percentage drop/rise in counts i.e. (23231-24218)/24218.&lt;/P&gt;

&lt;P&gt;I am providing region as input method which will return a table like above.&lt;BR /&gt;
Any help is appreciated&lt;BR /&gt;
Thanks a lot.&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 05:31:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-two-rows-of-a-table-if/m-p/500366#M139314</guid>
      <dc:creator>pulkit1997</dc:creator>
      <dc:date>2020-05-19T05:31:24Z</dc:date>
    </item>
  </channel>
</rss>

