<?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 split count of events based on conditions? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-count-of-events-based-on-conditions/m-p/309870#M92970</link>
    <description>&lt;P&gt;oh, you had to go and do it in two lines!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval Foo="x1 x2 x3 x1 x4 x2 x1 x3 x5 x2"| makemv Foo | mvexpand Foo 
| eval Bar="0 0 0 1 2 3" | makemv Bar | mvexpand Bar
| eval rand=random() | eval Bar = Bar + tonumber(substr(rand,1,1))

| eval type=if(Bar&amp;gt;5,"Bar&amp;gt;5","Bar=&amp;lt;5")
| chart count over Foo by type
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;results in &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Foo       Bar=&amp;lt;5    Bar&amp;gt;5               
x1        14        4                   
x2        12        6                   
x3        8         4                   
x4        3         3                   
x5        2         4                   
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 17 Feb 2017 16:12:23 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-02-17T16:12:23Z</dc:date>
    <item>
      <title>How to split count of events based on conditions?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-count-of-events-based-on-conditions/m-p/309863#M92963</link>
      <description>&lt;P&gt;Let's say that I have the following query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(...) | stats count AS Foo by X
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to split Foo based on conditions like Bar &amp;gt; 5 and Bar &amp;lt; 5, and display it as the following:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/2504iA85639AF7755C6A5/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 15:27:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-count-of-events-based-on-conditions/m-p/309863#M92963</guid>
      <dc:creator>Yaichael</dc:creator>
      <dc:date>2017-02-17T15:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to split count of events based on conditions?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-count-of-events-based-on-conditions/m-p/309864#M92964</link>
      <description>&lt;P&gt;Your table doesn't seem to match your description of the query. is "Bar" really count?  What does "Event" in your table represent?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 15:41:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-count-of-events-based-on-conditions/m-p/309864#M92964</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2017-02-17T15:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to split count of events based on conditions?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-count-of-events-based-on-conditions/m-p/309865#M92965</link>
      <description>&lt;P&gt;See somesoni2's answer as more elegant.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Try this -&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval Bar="1 3 5 7 9 2 1 5 7 8 24 5 1 3 4" | makemv Bar | mvexpand bar 

| stats count AS Foo by Bar
| eval Bar4=if(Bar&amp;lt;5,Foo,0)
| eval Bar5=if(Bar&amp;lt;5,0,Foo)
| stats sum(Foo) as Foo, sum(Bar5) as "Bar&amp;gt;=5",sum(Bar4) as "Bar&amp;lt;5"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...producing output that looks like this -&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Foo       Bar&amp;gt;=5    Bar&amp;lt;5               
15        8         7                   
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There is never going to be more than one line of data, though, unless you have more than one dimension.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval x="x1 x2 x3 x1 x4 x2 x1 x3 x5 x2"| makemv x | mvexpand x 
| eval Bar="0 0 0 1 2 3" | makemv Bar | mvexpand Bar
| eval rand=random() | eval Bar = Bar + tonumber(substr(rand,1,1))

| stats count AS Foo by x Bar
| eval Bar4=if(Bar&amp;lt;5,Foo,0)
| eval Bar5=if(Bar&amp;lt;5,0,Foo)
| stats sum(Foo) as Foo, sum(Bar5) as "Bar&amp;gt;=5",sum(Bar4) as "Bar&amp;lt;5" by x
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...producing (random) output that looks like this - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;x         Foo       Bar&amp;gt;=5    Bar&amp;lt;5     
x1        18        10        8         
x2        18        2         16        
x3        12        2         10        
x4        6         3         3         
x5        6         5         1         
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Come to think of it, you may have meant this - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval Foo="x1 x2 x3 x1 x4 x2 x1 x3 x5 x2"| makemv Foo | mvexpand Foo 
| eval Bar="0 0 0 1 2 3" | makemv Bar | mvexpand Bar
| eval rand=random() | eval Bar = Bar + tonumber(substr(rand,1,1))

| stats count as foocount by Foo Bar
| eval Bar4=if(Bar&amp;lt;5,foocount,0)
| eval Bar5=if(Bar&amp;lt;5,0,foocount)
| stats sum(Bar5) as "Bar&amp;gt;=5",sum(Bar4) as "Bar&amp;lt;5" by Foo
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...producing this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Foo       Bar&amp;gt;=5    Bar&amp;lt;5               
x1        7         11                  
x2        6         12                  
x3        2         10                  
x4        2         4                   
x5        2         4               
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Feb 2017 15:49:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-count-of-events-based-on-conditions/m-p/309865#M92965</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-02-17T15:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to split count of events based on conditions?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-count-of-events-based-on-conditions/m-p/309866#M92966</link>
      <description>&lt;P&gt;Hi rjthibod,&lt;/P&gt;

&lt;P&gt;Thanks for the reply. &lt;/P&gt;

&lt;P&gt;The table is for showing how would I like output of the resulting query.&lt;/P&gt;

&lt;P&gt;No. Bar, in this case, is another numeric field that I would like to use for displaying the events.&lt;/P&gt;

&lt;P&gt;"Event" was changed to num, meaning the count of Foo itself, Foo under Bar &amp;gt; 5, and Bar &amp;lt; 5 conditions subsequently.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 15:55:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-count-of-events-based-on-conditions/m-p/309866#M92966</guid>
      <dc:creator>Yaichael</dc:creator>
      <dc:date>2017-02-17T15:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to split count of events based on conditions?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-count-of-events-based-on-conditions/m-p/309867#M92967</link>
      <description>&lt;P&gt;OK will post an answer below. Note, what about Bar == 5?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 16:00:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-count-of-events-based-on-conditions/m-p/309867#M92967</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2017-02-17T16:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to split count of events based on conditions?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-count-of-events-based-on-conditions/m-p/309868#M92968</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search | eval type=if(Bar&amp;gt;5,"Bar&amp;gt;5","Bar=&amp;lt;5")
| chart count over Foo by type
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Feb 2017 16:01:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-count-of-events-based-on-conditions/m-p/309868#M92968</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-02-17T16:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to split count of events based on conditions?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-count-of-events-based-on-conditions/m-p/309869#M92969</link>
      <description>&lt;P&gt;Something still isn't clear. What is Foo in your new description? Is it just the sum of the columns for Bar &amp;lt;=5 and Bar &amp;gt; 5? Is there some other field not shown?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 16:08:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-count-of-events-based-on-conditions/m-p/309869#M92969</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2017-02-17T16:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to split count of events based on conditions?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-count-of-events-based-on-conditions/m-p/309870#M92970</link>
      <description>&lt;P&gt;oh, you had to go and do it in two lines!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval Foo="x1 x2 x3 x1 x4 x2 x1 x3 x5 x2"| makemv Foo | mvexpand Foo 
| eval Bar="0 0 0 1 2 3" | makemv Bar | mvexpand Bar
| eval rand=random() | eval Bar = Bar + tonumber(substr(rand,1,1))

| eval type=if(Bar&amp;gt;5,"Bar&amp;gt;5","Bar=&amp;lt;5")
| chart count over Foo by type
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;results in &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Foo       Bar=&amp;lt;5    Bar&amp;gt;5               
x1        14        4                   
x2        12        6                   
x3        8         4                   
x4        3         3                   
x5        2         4                   
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Feb 2017 16:12:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-count-of-events-based-on-conditions/m-p/309870#M92970</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-02-17T16:12:23Z</dc:date>
    </item>
  </channel>
</rss>

