<?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 can I count same field from different sourcetypes? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-count-same-field-from-different-sourcetypes/m-p/313261#M93772</link>
    <description>&lt;P&gt;I have two sourcetypes. In both, there is a field present that has the same value in both but just another name, let's say Field1 en Field1a&lt;BR /&gt;
Normally each value is present in both. This can be more than once but then also in both. Sometimes the value is only present in 1 of the sourcetypes. I want to determine when this happens. I thought it would be easy by just counting the number of each value in both sources and when the two counts are different I would know. But somehow I am not able to do a count of them both, someone ideas?&lt;/P&gt;</description>
    <pubDate>Wed, 04 Apr 2018 14:30:20 GMT</pubDate>
    <dc:creator>Mike6960</dc:creator>
    <dc:date>2018-04-04T14:30:20Z</dc:date>
    <item>
      <title>How can I count same field from different sourcetypes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-count-same-field-from-different-sourcetypes/m-p/313261#M93772</link>
      <description>&lt;P&gt;I have two sourcetypes. In both, there is a field present that has the same value in both but just another name, let's say Field1 en Field1a&lt;BR /&gt;
Normally each value is present in both. This can be more than once but then also in both. Sometimes the value is only present in 1 of the sourcetypes. I want to determine when this happens. I thought it would be easy by just counting the number of each value in both sources and when the two counts are different I would know. But somehow I am not able to do a count of them both, someone ideas?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 14:30:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-count-same-field-from-different-sourcetypes/m-p/313261#M93772</guid>
      <dc:creator>Mike6960</dc:creator>
      <dc:date>2018-04-04T14:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: How can I count same field from different sourcetypes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-count-same-field-from-different-sourcetypes/m-p/313262#M93773</link>
      <description>&lt;P&gt;Does something like this help?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=blah sourcetype=sourcetypeA OR sourcetype=sourcetypeB | stats count(my_field) as count by sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Apr 2018 00:18:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-count-same-field-from-different-sourcetypes/m-p/313262#M93773</guid>
      <dc:creator>davpx</dc:creator>
      <dc:date>2018-04-05T00:18:37Z</dc:date>
    </item>
    <item>
      <title>Re: How can I count same field from different sourcetypes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-count-same-field-from-different-sourcetypes/m-p/313263#M93774</link>
      <description>&lt;P&gt;Thanks, but the 'my field' has a different name in both sourcetypes so I can't count by just one field&lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 06:19:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-count-same-field-from-different-sourcetypes/m-p/313263#M93774</guid>
      <dc:creator>Mike6960</dc:creator>
      <dc:date>2018-04-05T06:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: How can I count same field from different sourcetypes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-count-same-field-from-different-sourcetypes/m-p/313264#M93775</link>
      <description>&lt;P&gt;@Mike6960, you would need to create a &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Knowledge/Addaliasestofields"&gt;Field Alias Knowledge Object&lt;/A&gt; for one of the sourcetype to make both the fields names as same lets say Field1.&lt;/P&gt;

&lt;P&gt;If you are creating a Field Alias For &lt;CODE&gt;sourcetype B&lt;/CODE&gt; will have effect similar to following command &lt;CODE&gt;eval Field1=Field1a&lt;/CODE&gt;&lt;BR /&gt;
If you want to do something similar in your Splunk Query you can try the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=blah sourcetype=sourcetypeA OR sourcetype=sourcetypeB 
| rename  Field1a as Field1
| stats count by sourcetype Field1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Apr 2018 06:30:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-count-same-field-from-different-sourcetypes/m-p/313264#M93775</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-04-05T06:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: How can I count same field from different sourcetypes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-count-same-field-from-different-sourcetypes/m-p/313265#M93776</link>
      <description>&lt;P&gt;Hi @niketnilay,&lt;BR /&gt;
I've created a fieldalias and I use chart count by sourcetype 'and' Field1. I almost have the result I want. The result is now a table which shows which shows the Field1 and how many times its exists in each sourcetype. Now I want to see only the results where the counts are not equal....? &lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 06:46:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-count-same-field-from-different-sourcetypes/m-p/313265#M93776</guid>
      <dc:creator>Mike6960</dc:creator>
      <dc:date>2018-04-05T06:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: How can I count same field from different sourcetypes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-count-same-field-from-different-sourcetypes/m-p/313266#M93777</link>
      <description>&lt;P&gt;Instead of stats use chart,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;YourBaseSearch&amp;gt;
  | chart count by Field1 sourcetype 
  | search sourcetypeA!=sourcetypeB
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;YourBaseSearch&amp;gt;
 | chart count over Field1 by sourcetype 
  | search sourcetypeA!=sourcetypeB
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Apr 2018 08:22:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-count-same-field-from-different-sourcetypes/m-p/313266#M93777</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-04-05T08:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: How can I count same field from different sourcetypes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-count-same-field-from-different-sourcetypes/m-p/313267#M93778</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/201110"&gt;@niketn&lt;/a&gt; , I produced this :&lt;BR /&gt;
Fieldalias for B_C and B_X is B_C_X&lt;/P&gt;

&lt;P&gt;| eval B_C_X  =ltrim(tostring(B_C_X  ),"0")&lt;BR /&gt;
| chart count(B_C) as T count(B_X) as T2 by B_C_X&lt;BR /&gt;&lt;BR /&gt;
| where T!= T2 &lt;BR /&gt;
| fillnull&lt;/P&gt;

&lt;P&gt;if I use 'search' instead of 'where' I still get mutiple rows with all the results.  Now I only need to figure out how to show the sourcetype in the result&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:52:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-count-same-field-from-different-sourcetypes/m-p/313267#M93778</guid>
      <dc:creator>Mike6960</dc:creator>
      <dc:date>2020-09-29T18:52:44Z</dc:date>
    </item>
  </channel>
</rss>

