<?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: Why is tstats command with eval not working on a particular field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-is-tstats-command-with-eval-not-working-on-a-particular/m-p/382541#M111777</link>
    <description>&lt;P&gt;I was able to get the results.  Realized that we were not using the actual field app_type with GROUPBY  in the tstats base search .. doing the following returned the expected results and I have validated them to be true. &lt;/P&gt;

&lt;P&gt;| tstats count from datamodel=Enc where sourcetype=trace Enc.type=TRACE Enc.cid=1234567 GROUBPBY Enc.app_type &lt;BR /&gt;
| drop_dm_object_name("Enc")&lt;BR /&gt;
| eval Call=if(app_type=="API", "sdk","non-sdk") &lt;BR /&gt;
| stats sum(count) by Call&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 21:19:30 GMT</pubDate>
    <dc:creator>nmohammed</dc:creator>
    <dc:date>2020-09-29T21:19:30Z</dc:date>
    <item>
      <title>Why is tstats command with eval not working on a particular field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-tstats-command-with-eval-not-working-on-a-particular/m-p/382538#M111774</link>
      <description>&lt;P&gt;hi, &lt;/P&gt;

&lt;P&gt;I am trying to combine results into two categories based of an eval statement. &lt;/P&gt;

&lt;P&gt;The original query returns the results fine, but is slow because of large amount of results and extended time frame:  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=enc sourcetype=enc type=trace source=*123456*|  eval  Call = if(app_type="API", "sdk", "non-sdk") |  stats count by Call
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried the following with &lt;CODE&gt;tstats&lt;/CODE&gt;, but none of them work, meaning displayed 0 results.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count from datamodel=Enc where sourcetype=trace  Enc.type=TRACE  Enc.cid=1234567 Enc.app_type=* 
| `drop_dm_object_name("Enc")`
| eval Call=if(app_type=="API", "sdk","non-sdk") 
| stats sum(count) by Call
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;AND &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats  count from datamodel=Enc where sourcetype=enc-trace  Enc.type=TRACE  Enc.cid=1234567
| `drop_dm_object_name("Enc")` 
| eval sdk=if(app_type="API",count,0), non-sdk=if(app_type!="API",count,0) 
| stats sum(sdk) as SDK, sum(non-sdk) as NON-SDK
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;appreciate help and ideas from Splunkers. &lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 15 Sep 2018 00:23:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-tstats-command-with-eval-not-working-on-a-particular/m-p/382538#M111774</guid>
      <dc:creator>nmohammed</dc:creator>
      <dc:date>2018-09-15T00:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: Why is tstats command with eval not working on a particular field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-tstats-command-with-eval-not-working-on-a-particular/m-p/382539#M111775</link>
      <description>&lt;P&gt;try adding prestats=true to your tstats commands.&lt;/P&gt;

&lt;P&gt;Thats always needed if you're going to feed tstats into timechart, stats, etc.&lt;/P&gt;

&lt;P&gt;For example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats prestats=true count from datamodel=Enc where sourcetype=trace Enc.type=TRACE Enc.cid=1234567 Enc.app_type=* 
| drop_dm_object_name("Enc")
| eval Call=if(app_type=="API", "sdk","non-sdk") 
| stats sum(count) by Call
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 15 Sep 2018 10:20:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-tstats-command-with-eval-not-working-on-a-particular/m-p/382539#M111775</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2018-09-15T10:20:58Z</dc:date>
    </item>
    <item>
      <title>Re: Why is tstats command with eval not working on a particular field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-tstats-command-with-eval-not-working-on-a-particular/m-p/382540#M111776</link>
      <description>&lt;P&gt;Thanks jkat54. &lt;/P&gt;

&lt;P&gt;adding prestats=true displays blank results with a single column non-sdk&lt;BR /&gt;
 | tstats prestats=true count from datamodel=Enc where sourcetype=trace Enc.type=TRACE Enc.cid=1234567 Enc.app_type=* &lt;BR /&gt;
 | drop_dm_object_name("Enc")&lt;BR /&gt;
 | eval Call=if(app_type=="API", "sdk","non-sdk") &lt;BR /&gt;
 | stats sum(count) by Call&lt;/P&gt;

&lt;P&gt;results - &lt;/P&gt;

&lt;P&gt;Call    sum(count)&lt;BR /&gt;
non-sdk  &lt;/P&gt;

&lt;P&gt;index=enc sourcetype=enc type=trace source=123456| eval Call = if(app_type="API", "sdk", "non-sdk") | stats count by Call&lt;/P&gt;

&lt;P&gt;Call    count&lt;BR /&gt;
non-sdk 1144197&lt;BR /&gt;
sdk 513994&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:19:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-tstats-command-with-eval-not-working-on-a-particular/m-p/382540#M111776</guid>
      <dc:creator>nmohammed</dc:creator>
      <dc:date>2020-09-29T21:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: Why is tstats command with eval not working on a particular field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-tstats-command-with-eval-not-working-on-a-particular/m-p/382541#M111777</link>
      <description>&lt;P&gt;I was able to get the results.  Realized that we were not using the actual field app_type with GROUPBY  in the tstats base search .. doing the following returned the expected results and I have validated them to be true. &lt;/P&gt;

&lt;P&gt;| tstats count from datamodel=Enc where sourcetype=trace Enc.type=TRACE Enc.cid=1234567 GROUBPBY Enc.app_type &lt;BR /&gt;
| drop_dm_object_name("Enc")&lt;BR /&gt;
| eval Call=if(app_type=="API", "sdk","non-sdk") &lt;BR /&gt;
| stats sum(count) by Call&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:19:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-tstats-command-with-eval-not-working-on-a-particular/m-p/382541#M111777</guid>
      <dc:creator>nmohammed</dc:creator>
      <dc:date>2020-09-29T21:19:30Z</dc:date>
    </item>
  </channel>
</rss>

