<?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 create a timechart using eval to create the fields and control the values by date? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-timechart-using-eval-to-create-the-fields-and/m-p/273076#M82270</link>
    <description>&lt;P&gt;There's a few ways to do this.  Here's one:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|gentimes start="12/1/2015" end="12/15/2015" | convert timeformat="%m/%d/%Y" ctime(starttime) AS mytime| eval xy=if(mytime&amp;gt;"12/10/2015",150,100) | fields mytime xy
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I do a lot of goofiness to get the days in the right format which you shouldn't have to do.  The key is the &lt;CODE&gt;eval&lt;/CODE&gt; statement.  All the stuff leading up to that just generates a set of dates through the first half of December, then converts the created "starttime" from a unix epoch value into a "regular date" named mytime (well, regular for North Americans, mostly, but close enough for others to figure it out).  I do that mostly so you can see the precise use case you seemed to need, that of doing date comparison.&lt;/P&gt;

&lt;P&gt;Then the eval just says if mytime is bigger than 12/10/2015 to make it 150, otherwise make it 100.&lt;BR /&gt;&lt;BR /&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/890i8A2D269C9EF1EC73/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;&lt;STRONG&gt;For more complex logic&lt;/STRONG&gt;, you could use (re-wrapped because it got a bit long)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|gentimes start="12/1/2015" end="12/15/2015" 
| convert timeformat="%m/%d/%Y" ctime(starttime) AS mytime
| eval xy=case(mytime&amp;gt;"12/05/2015" AND mytime&amp;lt;"12/10/2015",150,1==1,100) 
| fields mytime xy
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Case does a "test1", "val1 if test1 was true", test2, "val2 if test2 was true", etc...  The "1==1" is always true, so that sets the last one as a default of sorts.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Dec 2015 22:09:55 GMT</pubDate>
    <dc:creator>Richfez</dc:creator>
    <dc:date>2015-12-15T22:09:55Z</dc:date>
    <item>
      <title>How to create a timechart using eval to create the fields and control the values by date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-timechart-using-eval-to-create-the-fields-and/m-p/273075#M82269</link>
      <description>&lt;P&gt;I think this can be done, but I am having some troubles...&lt;/P&gt;

&lt;P&gt;This is what i am starting with, but not sure how to get it more like what I want below: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|gentimes start=-1 | eval temp=100 | eval count="ColumChart2" | table temp count | append [|stats count|eval count="END OF FILE"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I am hoping for is something like (excuse my code, it is more an explanation at this stage): &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval x = 100 | where date &amp;gt;=1/1/2014 AND date &amp;lt;=9/1/2014 | 
eval y = 150 | where date &amp;gt;=10/1/2014 AND date &amp;lt;=16/1/2014
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which I would hope would give me something like this graph: &lt;BR /&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/891iC6E93FB63B6E0925/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;And then ultimately I am holing for something like &lt;BR /&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/892iE20850A120D3CDFD/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Dec 2015 21:00:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-timechart-using-eval-to-create-the-fields-and/m-p/273075#M82269</guid>
      <dc:creator>HattrickNZ</dc:creator>
      <dc:date>2015-12-15T21:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a timechart using eval to create the fields and control the values by date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-timechart-using-eval-to-create-the-fields-and/m-p/273076#M82270</link>
      <description>&lt;P&gt;There's a few ways to do this.  Here's one:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|gentimes start="12/1/2015" end="12/15/2015" | convert timeformat="%m/%d/%Y" ctime(starttime) AS mytime| eval xy=if(mytime&amp;gt;"12/10/2015",150,100) | fields mytime xy
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I do a lot of goofiness to get the days in the right format which you shouldn't have to do.  The key is the &lt;CODE&gt;eval&lt;/CODE&gt; statement.  All the stuff leading up to that just generates a set of dates through the first half of December, then converts the created "starttime" from a unix epoch value into a "regular date" named mytime (well, regular for North Americans, mostly, but close enough for others to figure it out).  I do that mostly so you can see the precise use case you seemed to need, that of doing date comparison.&lt;/P&gt;

&lt;P&gt;Then the eval just says if mytime is bigger than 12/10/2015 to make it 150, otherwise make it 100.&lt;BR /&gt;&lt;BR /&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/890i8A2D269C9EF1EC73/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;&lt;STRONG&gt;For more complex logic&lt;/STRONG&gt;, you could use (re-wrapped because it got a bit long)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|gentimes start="12/1/2015" end="12/15/2015" 
| convert timeformat="%m/%d/%Y" ctime(starttime) AS mytime
| eval xy=case(mytime&amp;gt;"12/05/2015" AND mytime&amp;lt;"12/10/2015",150,1==1,100) 
| fields mytime xy
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Case does a "test1", "val1 if test1 was true", test2, "val2 if test2 was true", etc...  The "1==1" is always true, so that sets the last one as a default of sorts.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Dec 2015 22:09:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-timechart-using-eval-to-create-the-fields-and/m-p/273076#M82270</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2015-12-15T22:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a timechart using eval to create the fields and control the values by date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-timechart-using-eval-to-create-the-fields-and/m-p/273077#M82271</link>
      <description>&lt;P&gt;beautiful answer, 1 pet hate I have is that date format &lt;CODE&gt;%m/%d/%Y&lt;/CODE&gt; but thats just me. tks&lt;/P&gt;</description>
      <pubDate>Tue, 15 Dec 2015 22:25:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-timechart-using-eval-to-create-the-fields-and/m-p/273077#M82271</guid>
      <dc:creator>HattrickNZ</dc:creator>
      <dc:date>2015-12-15T22:25:34Z</dc:date>
    </item>
  </channel>
</rss>

