<?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: Problematic behavior with chart and last() in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Problematic-behavior-with-chart-and-last/m-p/75368#M19040</link>
    <description>&lt;P&gt;Nice.  Thanks. I'd forgotten about xyseries. I think there's a typo in your answer though -- either dont have the 'as ldr'  or replace "last(date_hour)" with "ldr".   I did the former and it started  working correctly.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Apr 2011 10:19:51 GMT</pubDate>
    <dc:creator>sideview</dc:creator>
    <dc:date>2011-04-06T10:19:51Z</dc:date>
    <item>
      <title>Problematic behavior with chart and last()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Problematic-behavior-with-chart-and-last/m-p/75365#M19037</link>
      <description>&lt;P&gt;So I have a dashboard and I want to display the most recent value of fieldA,  for each value of fieldB and fieldC, shown as a table where values of fieldB are down the left, and values of fieldC are across the top.   &lt;/P&gt;

&lt;P&gt;This is simple enough -- you just use the chart command. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;* | chart last(fieldA) over fieldB by fieldC
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and we &lt;EM&gt;should&lt;/EM&gt; end up with a table like: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;fieldB         |   fieldC_value1  |   fieldC_value1    | fieldC_value1  |
fieldB_value1  |        128.3     |      active        |     0.412      | 
fieldB_value2  |         99.3     |      active        |     0.31       |
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Except my data has some non-numeric values of fieldC (note the 'active' values above). 
And the &lt;CODE&gt;chart&lt;/CODE&gt; command doesnt like non-numeric values;  it throws them away.  &lt;/P&gt;

&lt;P&gt;So what happens, since is there is no numeric value for fieldC anywhere, my 'active' column disappears entirely.   Likewise &lt;CODE&gt;chart last(fieldC)&lt;/CODE&gt; is always null, whereas &lt;CODE&gt;stats last(fieldC)&lt;/CODE&gt; is always correct.&lt;/P&gt;

&lt;P&gt;Once you know to look for this spooky behavior it's pretty easy to reproduce.  Here's an example:  &lt;/P&gt;

&lt;P&gt;1) &lt;CODE&gt;* | head 10000 | chart last(date_hour) over date_second by date_minute&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;you may have to adjust the 10000, but this should show a result with 60 rows, with one for each second.&lt;/P&gt;

&lt;P&gt;Sneak in the following eval clause, which sets the date_hour field to "mayhem" whenever the date_second field is equal to '0'. &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;* | head 10000 | eval date_hour=if(searchmatch("date_second=0"),"mayhem",date_hour) | chart last(date_hour) over date_second by date_minute&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Now the entire 0th row dissappears and you only have 59 results.&lt;/P&gt;

&lt;P&gt;Question:   Is there some search language trick that can get me the end result I want?   I dont actually know any of the values ahead of time.  &lt;/P&gt;

&lt;P&gt;Is there some incantation I can use to simply turn off this behavior in chart?   &lt;/P&gt;

&lt;P&gt;NOTE: this is essentially the same issue that I brought up in &lt;A href="http://answers.splunk.com/questions/2295/how-come-some-fields-disappear-when-they-go-into-timechart-chart" rel="nofollow"&gt;http://answers.splunk.com/questions/2295/how-come-some-fields-disappear-when-they-go-into-timechart-chart&lt;/A&gt;,  except in that case I could work around the problem by using stats by _time, and here I dont see any workaround.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2011 08:20:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Problematic-behavior-with-chart-and-last/m-p/75365#M19037</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2011-04-06T08:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: Problematic behavior with chart and last()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Problematic-behavior-with-chart-and-last/m-p/75366#M19038</link>
      <description>&lt;P&gt;This should do the trick&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats last(date_hour) by date_second date_minute | xyseries date_second date_minute last(date_hour)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Apr 2011 09:59:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Problematic-behavior-with-chart-and-last/m-p/75366#M19038</guid>
      <dc:creator>steveyz</dc:creator>
      <dc:date>2011-04-06T09:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: Problematic behavior with chart and last()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Problematic-behavior-with-chart-and-last/m-p/75367#M19039</link>
      <description>&lt;P&gt;You can still use stats with xyseries:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;* | head 10000 
  | eval date_hour=if(searchmatch("date_second=0"),"mayhem",date_hour) 
  | chart last(date_hour) over date_second by date_minute
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;becomes&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;* | head 10000 
  | eval date_hour=if(searchmatch("date_second=0"),"mayhem",date_hour) 
  | stats last(date_hour) by date_second , date_minute 
  | xyseries date_second date_minute "last(date_hour)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Apr 2011 10:01:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Problematic-behavior-with-chart-and-last/m-p/75367#M19039</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2011-04-06T10:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: Problematic behavior with chart and last()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Problematic-behavior-with-chart-and-last/m-p/75368#M19040</link>
      <description>&lt;P&gt;Nice.  Thanks. I'd forgotten about xyseries. I think there's a typo in your answer though -- either dont have the 'as ldr'  or replace "last(date_hour)" with "ldr".   I did the former and it started  working correctly.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2011 10:19:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Problematic-behavior-with-chart-and-last/m-p/75368#M19040</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2011-04-06T10:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: Problematic behavior with chart and last()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Problematic-behavior-with-chart-and-last/m-p/75369#M19041</link>
      <description>&lt;P&gt;fixed typo/copy-paste error&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2011 10:41:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Problematic-behavior-with-chart-and-last/m-p/75369#M19041</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2011-04-06T10:41:59Z</dc:date>
    </item>
  </channel>
</rss>

