<?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: Trying to get stats output for 2 fields after the &amp;quot;by&amp;quot; in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-stats-output-for-2-fields-after-the-quot-by-quot/m-p/389505#M171097</link>
    <description>&lt;P&gt;You should just be able to do :&lt;/P&gt;

&lt;P&gt;sourcetype="sourcetype1"| where event="yes" | eval aTotal=if(myField="a", 1, 0) | eval bTotal=if(myField="b", 1, 0) | eval cTotal=if(myField="c", 1, 0) | stats sum(aTotal) as A, sum(bTotal) as B, sum(cTotal) as C by "myHost", "myCategory"&lt;/P&gt;</description>
    <pubDate>Wed, 22 May 2019 22:23:41 GMT</pubDate>
    <dc:creator>stoutrw</dc:creator>
    <dc:date>2019-05-22T22:23:41Z</dc:date>
    <item>
      <title>Trying to get stats output for 2 fields after the "by"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-stats-output-for-2-fields-after-the-quot-by-quot/m-p/389504#M171096</link>
      <description>&lt;P&gt;I have data that looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;event,myField,myHost,myCategory
yes,a,host1,category1
yes,b,host1,category1
yes,c,host2,category1
yes,a,host2,category3
yes,b,host2,category2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here's my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="sourcetype1"| where event="yes" | eval aTotal=if(myField="a", 1, 0) | eval bTotal=if(myField="b", 1, 0) | eval cTotal=if(myField="c", 1, 0) | stats sum(aTotal) as A, sum(bTotal) as B, sum(cTotal) as C by "myHost"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So currently my output looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;myHost, A, B, C
host1, 1, 1, 0
host2, 1, 1, 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm looking to get output that looks like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;myHost, myCategory, A, B, C
host1, category1, 1, 1, 0
host2, category1, 0, 0, 1
host2, category2, 0, 1, 0
host2, category3, 1, 0, 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Can anyone help?&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 21:05:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-stats-output-for-2-fields-after-the-quot-by-quot/m-p/389504#M171096</guid>
      <dc:creator>dsong555</dc:creator>
      <dc:date>2019-05-22T21:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get stats output for 2 fields after the "by"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-stats-output-for-2-fields-after-the-quot-by-quot/m-p/389505#M171097</link>
      <description>&lt;P&gt;You should just be able to do :&lt;/P&gt;

&lt;P&gt;sourcetype="sourcetype1"| where event="yes" | eval aTotal=if(myField="a", 1, 0) | eval bTotal=if(myField="b", 1, 0) | eval cTotal=if(myField="c", 1, 0) | stats sum(aTotal) as A, sum(bTotal) as B, sum(cTotal) as C by "myHost", "myCategory"&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 22:23:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-stats-output-for-2-fields-after-the-quot-by-quot/m-p/389505#M171097</guid>
      <dc:creator>stoutrw</dc:creator>
      <dc:date>2019-05-22T22:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get stats output for 2 fields after the "by"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-stats-output-for-2-fields-after-the-quot-by-quot/m-p/389506#M171098</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval data=" yes,a,host1,category1|yes,b,host1,category1|yes,c,host2,category1|yes,a,host2,category3|yes,b,host2,category2" | makemv data delim="|" | mvexpand data | rex field=data "(?&amp;lt;event&amp;gt;[^\,]*)\,(?&amp;lt;myField&amp;gt;[^\,]*)\,(?&amp;lt;myHost&amp;gt;[^\,]*)\,(?&amp;lt;myCategory&amp;gt;[^\,]*)$" | table event myField, myHost, myCategory | stats count(eval(myField=="a")) as A, count(eval(myField=="b")) as B, count(eval(myField=="c")) as C by myHost, myCategory
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 May 2019 00:04:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-stats-output-for-2-fields-after-the-quot-by-quot/m-p/389506#M171098</guid>
      <dc:creator>nabeel652</dc:creator>
      <dc:date>2019-05-23T00:04:35Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get stats output for 2 fields after the "by"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-stats-output-for-2-fields-after-the-quot-by-quot/m-p/389507#M171099</link>
      <description>&lt;P&gt;Thank you.  I swear I tried using two fields after the 'by' in the stats command earlier and it didn't work, but I'm glad it works now.&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2019 17:27:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-stats-output-for-2-fields-after-the-quot-by-quot/m-p/389507#M171099</guid>
      <dc:creator>dsong555</dc:creator>
      <dc:date>2019-05-23T17:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get stats output for 2 fields after the "by"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-stats-output-for-2-fields-after-the-quot-by-quot/m-p/389508#M171100</link>
      <description>&lt;P&gt;Glad it works!&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2019 17:39:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-stats-output-for-2-fields-after-the-quot-by-quot/m-p/389508#M171100</guid>
      <dc:creator>stoutrw</dc:creator>
      <dc:date>2019-05-23T17:39:49Z</dc:date>
    </item>
  </channel>
</rss>

