<?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 Why can't results can be shown when calculating the difference between two columns from two searches? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-can-t-results-can-be-shown-when-calculating-the-difference/m-p/433987#M123902</link>
    <description>&lt;P&gt;Here is my query :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="basicdataapi" source="/data/api-process/logs/equitydata-rawdata-producer/application.log" 
service_name="equitydata-rawdata-producer"
 host="daasynprdbd6012" CountFlag="true" PackageDataType |stats count by PackageDataType | append[search  
 index=datasvc source="us-east-1:/aws/lambda/ged-equitydata-rawdata-consumer*" 
 service_name="equitydata-rawdata-consumer" CountFlag="true" 
 PackageDataType |stats count by PackageDataType ]|**table DataPackageType num |streamstats max(num) as max min(num) as min by PackageDataType | eval diff=max-min | dedup DataPackageType | table DataPackageType max min diff.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I run the above query which have been marked as "Strong" font, I can get a result like this:&lt;BR /&gt;
PackageDataType                              num&lt;BR /&gt;
CO                                                319&lt;BR /&gt;
SO                                                420&lt;BR /&gt;
CO                                                319&lt;BR /&gt;
SO                                                420&lt;/P&gt;

&lt;P&gt;But I want to count the difference between same "PackageDataType", like below format:&lt;BR /&gt;
PackageDataType           max    min      diff&lt;BR /&gt;
CO                                      319     319        0&lt;BR /&gt;
SO                                       420     420       0&lt;/P&gt;

&lt;P&gt;So I added "streamstats.." to count it . But after I added it , no result can be shown.  Is there anything wrong ?&lt;/P&gt;</description>
    <pubDate>Sun, 14 Oct 2018 02:58:39 GMT</pubDate>
    <dc:creator>asdusert</dc:creator>
    <dc:date>2018-10-14T02:58:39Z</dc:date>
    <item>
      <title>Why can't results can be shown when calculating the difference between two columns from two searches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-can-t-results-can-be-shown-when-calculating-the-difference/m-p/433987#M123902</link>
      <description>&lt;P&gt;Here is my query :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="basicdataapi" source="/data/api-process/logs/equitydata-rawdata-producer/application.log" 
service_name="equitydata-rawdata-producer"
 host="daasynprdbd6012" CountFlag="true" PackageDataType |stats count by PackageDataType | append[search  
 index=datasvc source="us-east-1:/aws/lambda/ged-equitydata-rawdata-consumer*" 
 service_name="equitydata-rawdata-consumer" CountFlag="true" 
 PackageDataType |stats count by PackageDataType ]|**table DataPackageType num |streamstats max(num) as max min(num) as min by PackageDataType | eval diff=max-min | dedup DataPackageType | table DataPackageType max min diff.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I run the above query which have been marked as "Strong" font, I can get a result like this:&lt;BR /&gt;
PackageDataType                              num&lt;BR /&gt;
CO                                                319&lt;BR /&gt;
SO                                                420&lt;BR /&gt;
CO                                                319&lt;BR /&gt;
SO                                                420&lt;/P&gt;

&lt;P&gt;But I want to count the difference between same "PackageDataType", like below format:&lt;BR /&gt;
PackageDataType           max    min      diff&lt;BR /&gt;
CO                                      319     319        0&lt;BR /&gt;
SO                                       420     420       0&lt;/P&gt;

&lt;P&gt;So I added "streamstats.." to count it . But after I added it , no result can be shown.  Is there anything wrong ?&lt;/P&gt;</description>
      <pubDate>Sun, 14 Oct 2018 02:58:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-can-t-results-can-be-shown-when-calculating-the-difference/m-p/433987#M123902</guid>
      <dc:creator>asdusert</dc:creator>
      <dc:date>2018-10-14T02:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: Why can't results can be shown when calculating the difference between two columns from two searches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-can-t-results-can-be-shown-when-calculating-the-difference/m-p/433988#M123903</link>
      <description>&lt;P&gt;@asdusert,&lt;/P&gt;

&lt;P&gt;From your search, there are possibly two things you might need to change to get the desired result&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;In your original search you are using field name &lt;STRONG&gt;PackageDataType&lt;/STRONG&gt; but in the table command next to it, you are using &lt;STRONG&gt;DataPackageType&lt;/STRONG&gt; which are different field names for splunk and that's the reason you are not getting the result.&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;streamstats gives you &lt;CODE&gt;streaming&lt;/CODE&gt; max or min. ie.when the streamstats look at the first event, it only knows CO 319 and hence it would result 319 as max and min for CO even though the second CO has a different count say 219. You may test it by running&lt;/P&gt;

&lt;P&gt;index=_*|stats count by sourcetype ,index|fields - sourcetype|streamstats max(count) as max,min(count) as min by index&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;So try &lt;CODE&gt;stats&lt;/CODE&gt; or &lt;CODE&gt;eventstats&lt;/CODE&gt; for the final calculation.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="basicdataapi" source="/data/api-process/logs/equitydata-rawdata-producer/application.log" 
service_name="equitydata-rawdata-producer"
host="daasynprdbd6012" CountFlag="true" PackageDataType |stats count by PackageDataType 
| append[search index=datasvc source="us-east-1:/aws/lambda/ged-equitydata-rawdata-consumer*" 
service_name="equitydata-rawdata-consumer" CountFlag="true" 
|stats count by PackageDataType ]
|stats max(num) as max min(num) as min by PackageDataType | eval diff=max-min
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To your original search, just add &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; |stats max(num) as max min(num) as min by PackageDataType | eval diff=max-min
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Oct 2018 04:39:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-can-t-results-can-be-shown-when-calculating-the-difference/m-p/433988#M123903</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-10-14T04:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: Why can't results can be shown when calculating the difference between two columns from two searches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-can-t-results-can-be-shown-when-calculating-the-difference/m-p/433989#M123904</link>
      <description>&lt;P&gt;@renjith.nair  Thanks so much . it works.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Oct 2018 09:40:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-can-t-results-can-be-shown-when-calculating-the-difference/m-p/433989#M123904</guid>
      <dc:creator>asdusert</dc:creator>
      <dc:date>2018-10-14T09:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Why can't results can be shown when calculating the difference between two columns from two searches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-can-t-results-can-be-shown-when-calculating-the-difference/m-p/433990#M123905</link>
      <description>&lt;P&gt;@asdusert, glad that it worked. Kindly accept it as answer to close this thread. Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 14 Oct 2018 11:40:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-can-t-results-can-be-shown-when-calculating-the-difference/m-p/433990#M123905</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-10-14T11:40:40Z</dc:date>
    </item>
  </channel>
</rss>

