<?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: How to count distinct occurrences of one field based on another field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-distinct-occurrences-of-one-field-based-on-another/m-p/181690#M52362</link>
    <description>&lt;P&gt;Thanks a lot for your answer. I finally did something like this:&lt;BR /&gt;
    source="output.csv" | eval c2test=if(match(fullcommand, ".&lt;EM&gt;c2.&lt;/EM&gt;"),testname,null()) | stats dc(c2test) AS "Command2 Tests", dc(testname) AS AllTests | eval other = AllTests - $Command2 Tests$ | fields - AllTests | transpose&lt;/P&gt;

&lt;P&gt;I had to transpose the stats table to be able to show the data also in a Pie Chart. I saw that Pie charts only support 1 column as data and one column as labels for that data.&lt;BR /&gt;
Thanks again!&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jun 2015 08:37:28 GMT</pubDate>
    <dc:creator>raduenea</dc:creator>
    <dc:date>2015-06-30T08:37:28Z</dc:date>
    <item>
      <title>How to count distinct occurrences of one field based on another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-distinct-occurrences-of-one-field-based-on-another/m-p/181687#M52359</link>
      <description>&lt;P&gt;I have a CSV file similar to the one below:&lt;BR /&gt;
timestamp, fullcommand, testname, details&lt;BR /&gt;
time1, c1, test1, details1&lt;BR /&gt;
time2, c2, test1, details2&lt;BR /&gt;
time3, c3, test1, details3&lt;BR /&gt;
time4, c1, test2, details4&lt;BR /&gt;
time5, c3, test2, details5&lt;BR /&gt;
time6, c1, test3, details6&lt;BR /&gt;
time7, c2, test3, details7&lt;BR /&gt;
time8, c3, test3, details8&lt;BR /&gt;
time9, c4, test3, details9&lt;BR /&gt;
time10, c5, test4, details10&lt;BR /&gt;
... &lt;/P&gt;

&lt;P&gt;I'm trying to extract (and count) all tests that contain c2 and create a pie chart that should have 2 values: count of distinct tests that contain c2 and all other tests that don't contain c2 command in any of their csv entries.&lt;/P&gt;

&lt;P&gt;I'm using a search like the one below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="output.csv" | eval bool=if(match(fullcommand,".*c2.*"),"Command2 Tests", "Other tests") | chart dc(testname) as Tests by bool
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This seems to be getting me the correct c2 tests distinct count, but when counting all other tests I get the total amount of tests. I suspect this is because the tests that are matched by my if condition, also have entries that do not match my condition and therefore are counted also as tests that don't contain c2.&lt;/P&gt;

&lt;P&gt;Do you have any suggestion as to how I should build my search in order to get the desired result? Is it possible? or do I have to change the CSV structure somehow?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2015 14:46:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-distinct-occurrences-of-one-field-based-on-another/m-p/181687#M52359</guid>
      <dc:creator>raduenea</dc:creator>
      <dc:date>2015-06-29T14:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to count distinct occurrences of one field based on another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-distinct-occurrences-of-one-field-based-on-another/m-p/181688#M52360</link>
      <description>&lt;P&gt;Hello, Here is an option:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; source="output.csv" fullcommand="c2"|stats count(testname) as  "Command2 Tests"  |join [search source="output.csv"  fullcommand!="c2"|stats count(testname) as  "Other tests"  ] |table  "Command2 Tests" "Other tests" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2015 15:01:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-distinct-occurrences-of-one-field-based-on-another/m-p/181688#M52360</guid>
      <dc:creator>stephanefotso</dc:creator>
      <dc:date>2015-06-29T15:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to count distinct occurrences of one field based on another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-distinct-occurrences-of-one-field-based-on-another/m-p/181689#M52361</link>
      <description>&lt;P&gt;If I understand you correctly, this should do it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="output.csv" | eval c2test=if(match(fullcommand,".*c2.*"),testname,null()) | stats dc(c2test) AS "Command2 Tests" dc(testname) AS AllTests | eval "Other Tests" = AllTests - $Command2 Tests$ | fields - AllTests
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jun 2015 15:06:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-distinct-occurrences-of-one-field-based-on-another/m-p/181689#M52361</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-06-29T15:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to count distinct occurrences of one field based on another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-distinct-occurrences-of-one-field-based-on-another/m-p/181690#M52362</link>
      <description>&lt;P&gt;Thanks a lot for your answer. I finally did something like this:&lt;BR /&gt;
    source="output.csv" | eval c2test=if(match(fullcommand, ".&lt;EM&gt;c2.&lt;/EM&gt;"),testname,null()) | stats dc(c2test) AS "Command2 Tests", dc(testname) AS AllTests | eval other = AllTests - $Command2 Tests$ | fields - AllTests | transpose&lt;/P&gt;

&lt;P&gt;I had to transpose the stats table to be able to show the data also in a Pie Chart. I saw that Pie charts only support 1 column as data and one column as labels for that data.&lt;BR /&gt;
Thanks again!&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2015 08:37:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-distinct-occurrences-of-one-field-based-on-another/m-p/181690#M52362</guid>
      <dc:creator>raduenea</dc:creator>
      <dc:date>2015-06-30T08:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to count distinct occurrences of one field based on another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-distinct-occurrences-of-one-field-based-on-another/m-p/181691#M52363</link>
      <description>&lt;P&gt;Thanks a lot for your answer. I didn't manage to make it work like I wanted using your example. But you gave me an idea for another issue that I have. Thanks again!&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2015 08:38:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-distinct-occurrences-of-one-field-based-on-another/m-p/181691#M52363</guid>
      <dc:creator>raduenea</dc:creator>
      <dc:date>2015-06-30T08:38:43Z</dc:date>
    </item>
  </channel>
</rss>

