<?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: Data Model: TStats time-functions get latest NOT NULL in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Data-Model-TStats-time-functions-get-latest-NOT-NULL/m-p/483381#M135339</link>
    <description>&lt;P&gt;You are on the correct path, you should avoid using empty sets in any fields unless some very specific use cases.  Your evals should be this &lt;CODE&gt;EVAL-sensor_01 = if(valueName="raw_sensor_01", value, null())&lt;/CODE&gt; The &lt;CODE&gt;null()&lt;/CODE&gt; command makes it a null value instead of an empty set.&lt;/P&gt;</description>
    <pubDate>Wed, 15 Jan 2020 19:46:14 GMT</pubDate>
    <dc:creator>dmarling</dc:creator>
    <dc:date>2020-01-15T19:46:14Z</dc:date>
    <item>
      <title>Data Model: TStats time-functions get latest NOT NULL</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Data-Model-TStats-time-functions-get-latest-NOT-NULL/m-p/483379#M135337</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'm having trouble retrieving my fields from an accelerated data model.&lt;BR /&gt;
The main problem is that most of the fields are optional...&lt;BR /&gt;
lets say the corresponding sourcetype looks like this:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;asset_type (required)&lt;/LI&gt;
&lt;LI&gt;asset_id (required)&lt;/LI&gt;
&lt;LI&gt;sensor_01 (optional)&lt;/LI&gt;
&lt;LI&gt;sensor_02 (optional)&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;then two events could look like this:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;asset_type / asset_id / sensor_01 / sensor_02&lt;/STRONG&gt; &lt;BR /&gt;
"123" / "007" / "12.75" / ""&lt;BR /&gt;
"123" / "007" / "" / "1265.99"&lt;/P&gt;

&lt;P&gt;Now, when i search via the tstats command like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats summariesonly=t
latest(dm_main.sensor_01)
latest(dm_main.sensor_02)
FROM
datamodel=dm_main
by
dm_main.asset_type 
dm_main.asset_id
| rename dm_main.* AS *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I only get either a value for sensor_01 OR sensor_02, since the latest value for the other is a blank...&lt;BR /&gt;
I tried reaching around that by using list(), but its not available for tstats.&lt;BR /&gt;
Then I tried using values(), which gives me the values I need, but in alphabetically order. But I need to know the lastest.&lt;/P&gt;

&lt;P&gt;Is there a way with tstats to search for LATEST NOT NULL?&lt;/P&gt;

&lt;P&gt;additional info:&lt;/P&gt;

&lt;P&gt;the fields in Question are not native to the sourcetype, they are calculated fields:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EVAL-sensor_01 = if(valueName="raw_sensor_01", value, "")
EVAL-sensor_02 = if(valueName="raw_sensor_02", value, "")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:39:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Data-Model-TStats-time-functions-get-latest-NOT-NULL/m-p/483379#M135337</guid>
      <dc:creator>hbrandt84</dc:creator>
      <dc:date>2020-09-30T03:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: Data Model: TStats time-functions get latest NOT NULL</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Data-Model-TStats-time-functions-get-latest-NOT-NULL/m-p/483380#M135338</link>
      <description>&lt;P&gt;Okay, It seems like I need to change:&lt;BR /&gt;
EVAL-sensor_01 = if(valueName="raw_sensor_01", value, &lt;STRONG&gt;""&lt;/STRONG&gt;)&lt;/P&gt;

&lt;P&gt;to:&lt;BR /&gt;
EVAL-sensor_01 = if(valueName="raw_sensor_01", value, &lt;STRONG&gt;NULL&lt;/STRONG&gt;)&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:39:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Data-Model-TStats-time-functions-get-latest-NOT-NULL/m-p/483380#M135338</guid>
      <dc:creator>hbrandt84</dc:creator>
      <dc:date>2020-09-30T03:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Data Model: TStats time-functions get latest NOT NULL</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Data-Model-TStats-time-functions-get-latest-NOT-NULL/m-p/483381#M135339</link>
      <description>&lt;P&gt;You are on the correct path, you should avoid using empty sets in any fields unless some very specific use cases.  Your evals should be this &lt;CODE&gt;EVAL-sensor_01 = if(valueName="raw_sensor_01", value, null())&lt;/CODE&gt; The &lt;CODE&gt;null()&lt;/CODE&gt; command makes it a null value instead of an empty set.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jan 2020 19:46:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Data-Model-TStats-time-functions-get-latest-NOT-NULL/m-p/483381#M135339</guid>
      <dc:creator>dmarling</dc:creator>
      <dc:date>2020-01-15T19:46:14Z</dc:date>
    </item>
  </channel>
</rss>

