<?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: Get the difference of 2 columns after Grouping in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Get-the-difference-of-2-columns-after-Grouping/m-p/162578#M46120</link>
    <description>&lt;P&gt;After your chart command, the values of Product Type becomes field names. So you'll have actual field names like 'Fruit' and 'Veg', that what's been used for calculation.&lt;/P&gt;</description>
    <pubDate>Thu, 06 Aug 2015 15:57:31 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2015-08-06T15:57:31Z</dc:date>
    <item>
      <title>Get the difference of 2 columns after Grouping</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-difference-of-2-columns-after-Grouping/m-p/162575#M46117</link>
      <description>&lt;P&gt;After grouping to display a chart, where there are only 2 values produced, how do I calculate the difference between the 2 columns?&lt;/P&gt;

&lt;P&gt;e.g. Sample search :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;search terms&amp;gt; | rex "Sent\s+(?&amp;lt;ProductType&amp;gt;[a-zA-Z]*)" | rex "Product:\s+(?&amp;lt;ProductId&amp;gt;[a-zA-Z0-9]{5}-[a-zA-Z0-9]{8})" | eval ProductType=if(ProductType="Apple", "Fruit", "Veg")  | chart count(ProductType) as Total by ProductId, ProductType
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Giving:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ProductId                Fruit      Veg
12345-12345678            3          2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Where I want:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ProductId                Fruit      Veg  Diff
12345-12345678            3          2    1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Aug 2015 10:42:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-difference-of-2-columns-after-Grouping/m-p/162575#M46117</guid>
      <dc:creator>GadgetGeek</dc:creator>
      <dc:date>2015-08-06T10:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: Get the difference of 2 columns after Grouping</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-difference-of-2-columns-after-Grouping/m-p/162576#M46118</link>
      <description>&lt;P&gt;If the ProductType is static, then the field name after chart will also be fixed, you can just use an eval to get the difference.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;search terms&amp;gt; | rex "Sent\s+(?&amp;lt;ProductType&amp;gt;[a-zA-Z]*)" | rex "Product:\s+(?&amp;lt;ProductId&amp;gt;[a-zA-Z0-9]{5}-[a-zA-Z0-9]{8})" | eval ProductType=if(ProductType="Apple", "Fruit", "Veg")  | chart count(ProductType) as Total by ProductId, ProductType | eval Diff=abs(Fruit-Veg)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Aug 2015 14:58:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-difference-of-2-columns-after-Grouping/m-p/162576#M46118</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-08-06T14:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: Get the difference of 2 columns after Grouping</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-difference-of-2-columns-after-Grouping/m-p/162577#M46119</link>
      <description>&lt;P&gt;It works - how does it work though, as "Fruit" and "Veg" are string values for 'ProductType'? It's kind of like:&lt;/P&gt;

&lt;P&gt;Diff=abs(ProductType="Fruit", ProductType="Veg)..&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2015 15:21:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-difference-of-2-columns-after-Grouping/m-p/162577#M46119</guid>
      <dc:creator>GadgetGeek</dc:creator>
      <dc:date>2015-08-06T15:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Get the difference of 2 columns after Grouping</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-difference-of-2-columns-after-Grouping/m-p/162578#M46120</link>
      <description>&lt;P&gt;After your chart command, the values of Product Type becomes field names. So you'll have actual field names like 'Fruit' and 'Veg', that what's been used for calculation.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2015 15:57:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-difference-of-2-columns-after-Grouping/m-p/162578#M46120</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-08-06T15:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: Get the difference of 2 columns after Grouping</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-difference-of-2-columns-after-Grouping/m-p/162579#M46121</link>
      <description>&lt;P&gt;Many thanks!!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Aug 2015 05:00:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-difference-of-2-columns-after-Grouping/m-p/162579#M46121</guid>
      <dc:creator>GadgetGeek</dc:creator>
      <dc:date>2015-08-07T05:00:16Z</dc:date>
    </item>
  </channel>
</rss>

