<?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 can I fill different values according to different conditions ? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-fill-different-values-according-to-different/m-p/391749#M166613</link>
    <description>&lt;P&gt;Thank you very much&lt;/P&gt;</description>
    <pubDate>Tue, 13 Nov 2018 16:59:31 GMT</pubDate>
    <dc:creator>WXY</dc:creator>
    <dc:date>2018-11-13T16:59:31Z</dc:date>
    <item>
      <title>How can I fill different values according to different conditions ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-fill-different-values-according-to-different/m-p/391747#M166611</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;

&lt;P&gt;Here's my SPL:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="last_f" 
     | stats count by level,sys_name _time 
     | eval rate=case(
         level== "critical", 0.5,
         level== "high", 0.3,
         level== "medium", 0.2,
         level== "low", 0) 
     | eval score=count*rate 
     | stats sum(score) as SCORE by sys_name  _time 
     | sort - SCORE 
     | streamstats latest(SCORE) as a by sys_name  current=f 
     | fillnull value=0 a 
     | eval aa = SCORE-a 
     | stats latest(_time) as _time count latest(a) as last_score latest(SCORE) as final_score latest(aa) as c_value by sys_name 
     | sort - final_score
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I can get a table such as :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sya_name         _time             count     last_score      final_score     c_value
 sys_n1      2018/10/11 10:02:12        3         2400             500               -1900
 sys_n2      2018/09/10 12:09:22        1         0                    179                179
 sys_n3      2018/11/01 17:02:34        2         400                500                100
 sys_n4      2018/08/12 14:02:42        2         550                450                -100
 sys_n5      2018/10/15 12:08:11        2         660                660                0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But I want to this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;If count==1 c_value="Only One"
if count&amp;gt;1&amp;amp;&amp;amp;c_value&amp;lt;0 c_value="Level Up" 
if count&amp;gt;1&amp;amp;&amp;amp;c_value&amp;gt;0  c_value="Level Down" 
if count&amp;gt;1&amp;amp;&amp;amp;c_value==0 c_value="Normal"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sya_name       time                   count     last_score      final_score     c_value
 sys_n1      2018/10/11 10:02:12        3           2400           500          Level Down
 sys_n2      2018/09/10 12:09:22        1           0                 179            Only One
 sys_n3      2018/11/01 17:02:34        2           400             500           Level Up
 sys_n4      2018/08/12 14:02:42        2           550             450          Level Down
 sys_n5      2018/10/15 12:08:11        2           660             660          Normal
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What should I do?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Nov 2018 08:11:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-fill-different-values-according-to-different/m-p/391747#M166611</guid>
      <dc:creator>WXY</dc:creator>
      <dc:date>2018-11-13T08:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: How can I fill different values according to different conditions ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-fill-different-values-according-to-different/m-p/391748#M166612</link>
      <description>&lt;P&gt;Not sure I've got the logic right but you could add the following line to your existing SPL.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval c_value = CASE ( count==1, "Only One", (count&amp;gt;1 and c_value&amp;gt;1), "Level Up", c_value&amp;lt;0, "Level Down", (count&amp;gt;1 and c_value==0), "Normal" )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hopefully the above shows the principle.&lt;/P&gt;

&lt;P&gt;A self-contained example showing this so people can test on thier own Splunk instances (everything upto the first eval c_value is generating the data)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=5
| streamstats count as row 
| eval _time = _time - row 
| eval count = CASE (row==1,3, row==2,1, 1==1, 2) 
| eval c_value = CASE ( row==1,-1900,row==2,170,row==3,100,row==4,-100,row==5,0)
| eval c_value = CASE ( count==1, "Only One", (count&amp;gt;1 and c_value&amp;gt;1), "Level Up", c_value&amp;lt;0, "Level Down", (count&amp;gt;1 and c_value==0), "Normal" )
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Nov 2018 13:12:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-fill-different-values-according-to-different/m-p/391748#M166612</guid>
      <dc:creator>msivill_splunk</dc:creator>
      <dc:date>2018-11-13T13:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: How can I fill different values according to different conditions ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-fill-different-values-according-to-different/m-p/391749#M166613</link>
      <description>&lt;P&gt;Thank you very much&lt;/P&gt;</description>
      <pubDate>Tue, 13 Nov 2018 16:59:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-fill-different-values-according-to-different/m-p/391749#M166613</guid>
      <dc:creator>WXY</dc:creator>
      <dc:date>2018-11-13T16:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: How can I fill different values according to different conditions ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-fill-different-values-according-to-different/m-p/391750#M166614</link>
      <description>&lt;P&gt;Thank you for accepting the answer&lt;/P&gt;</description>
      <pubDate>Tue, 13 Nov 2018 17:02:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-fill-different-values-according-to-different/m-p/391750#M166614</guid>
      <dc:creator>msivill_splunk</dc:creator>
      <dc:date>2018-11-13T17:02:13Z</dc:date>
    </item>
  </channel>
</rss>

