<?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 TSTATS using a lookup table for a variable? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/TSTATS-using-a-lookup-table-for-a-variable/m-p/634244#M220307</link>
    <description>&lt;P&gt;I am building a query where I want to use a top 10 list of values from a lookup table, and then run a search against those entries (each entry in a different query).&lt;/P&gt;
&lt;P&gt;The basic search is something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| tstats count as count where index="myindex" id="some id value" by _time CAUSE_VALUE span=5m 
| timechart sum(count) as total_count span=5min &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The query in the lookup table to provide the variable for the ID is something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| inputlookup lookuptable.csv
| sort 10 -dm
| table oper, dm
| transpose 10
| rename "row "* AS "value_in*"
| eval top1=value_in1&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TSTATS needs to be the first statement in the query, however with that being the case, I cant get the variable set before it.&lt;/P&gt;
&lt;P&gt;The perfect query should be something like this, however it is not (because of the above):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;'''~ Set Variable top1 ~'''
| inputlookup lookuptable.csv 
| sort 10 -dm
| table oper, dm 
| transpose 10 
| rename "row "* AS "value_in*"
| eval top1=value_in1
'''~ Use Variable ~'''
| tstats count as count where index="myindex" id=top1 by _time CAUSE_VALUE span=5m 
| timechart sum(count) as total_count span=5min&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did read some similar questions where it was suggested to use&amp;nbsp;&lt;FONT face="courier new,courier"&gt;|where id= &amp;lt;whatever&amp;gt;&amp;nbsp;&lt;/FONT&gt;but that doesn't work in my case because of the TSTATS.&lt;/P&gt;
&lt;P&gt;Any suggestions?&lt;/P&gt;</description>
    <pubDate>Mon, 13 Mar 2023 13:55:23 GMT</pubDate>
    <dc:creator>lennys26</dc:creator>
    <dc:date>2023-03-13T13:55:23Z</dc:date>
    <item>
      <title>TSTATS using a lookup table for a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/TSTATS-using-a-lookup-table-for-a-variable/m-p/634244#M220307</link>
      <description>&lt;P&gt;I am building a query where I want to use a top 10 list of values from a lookup table, and then run a search against those entries (each entry in a different query).&lt;/P&gt;
&lt;P&gt;The basic search is something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| tstats count as count where index="myindex" id="some id value" by _time CAUSE_VALUE span=5m 
| timechart sum(count) as total_count span=5min &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The query in the lookup table to provide the variable for the ID is something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| inputlookup lookuptable.csv
| sort 10 -dm
| table oper, dm
| transpose 10
| rename "row "* AS "value_in*"
| eval top1=value_in1&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TSTATS needs to be the first statement in the query, however with that being the case, I cant get the variable set before it.&lt;/P&gt;
&lt;P&gt;The perfect query should be something like this, however it is not (because of the above):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;'''~ Set Variable top1 ~'''
| inputlookup lookuptable.csv 
| sort 10 -dm
| table oper, dm 
| transpose 10 
| rename "row "* AS "value_in*"
| eval top1=value_in1
'''~ Use Variable ~'''
| tstats count as count where index="myindex" id=top1 by _time CAUSE_VALUE span=5m 
| timechart sum(count) as total_count span=5min&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did read some similar questions where it was suggested to use&amp;nbsp;&lt;FONT face="courier new,courier"&gt;|where id= &amp;lt;whatever&amp;gt;&amp;nbsp;&lt;/FONT&gt;but that doesn't work in my case because of the TSTATS.&lt;/P&gt;
&lt;P&gt;Any suggestions?&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 13:55:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/TSTATS-using-a-lookup-table-for-a-variable/m-p/634244#M220307</guid>
      <dc:creator>lennys26</dc:creator>
      <dc:date>2023-03-13T13:55:23Z</dc:date>
    </item>
    <item>
      <title>Re: TSTATS using a lookup table for a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/TSTATS-using-a-lookup-table-for-a-variable/m-p/634255#M220318</link>
      <description>&lt;P&gt;Try using a subsearch to set the variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats count as count where index="myindex" [ | inputlookup lookuptable.csv 
  | sort 10 -dm
  | table oper, dm 
  | transpose 10 
  | rename "row "* AS "value_in*"
  | eval top1=value_in1
  | return id=top1 ] by _time CAUSE_VALUE span=5m 
| timechart sum(count) as total_count span=5min&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 15:37:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/TSTATS-using-a-lookup-table-for-a-variable/m-p/634255#M220318</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-03-13T15:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: TSTATS using a lookup table for a variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/TSTATS-using-a-lookup-table-for-a-variable/m-p/634256#M220319</link>
      <description>&lt;P&gt;Your search is a bit confusing but seems to be just using the top value and I am presuming that you want the id to match the oper from the sorted list?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats count as count where index="myindex" [ | inputlookup lookuptable.csv 
  | sort 10 -dm
  | head 1 
  | rename oper as id
  | fields id
  | format ] by _time CAUSE_VALUE span=5m 
| timechart sum(count) as total_count span=5min&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 12:35:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/TSTATS-using-a-lookup-table-for-a-variable/m-p/634256#M220319</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-03-13T12:35:58Z</dc:date>
    </item>
    <item>
      <title>Re: TSTATS using a lookup table for a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/TSTATS-using-a-lookup-table-for-a-variable/m-p/634286#M220341</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;&amp;nbsp;. Thanks -- I do believe that the subsearch is the answer, however both of the queries only insert the value, but do not have the fieldname (id).&lt;/P&gt;&lt;P&gt;In the TSTATS I need to have an &lt;FONT face="courier new,courier"&gt;id=id&lt;/FONT&gt; (&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;'s solution) or an &lt;FONT face="courier new,courier"&gt;id=top1&lt;/FONT&gt; (&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;'s solution).&lt;/P&gt;&lt;P&gt;When I try either of the below, it does not work.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats count as count where index="titan" sourcetype="titan:cdr*" ID=top1 ROUTING_CDN!=BA* REL_CAUSE=* 
    [| inputlookup
...&lt;/LI-CODE&gt;&lt;P&gt;OR&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats count as count where index="titan" sourcetype="titan:cdr*" ID=id ROUTING_CDN!=BA* REL_CAUSE=* 
    [| inputlookup
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 15:01:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/TSTATS-using-a-lookup-table-for-a-variable/m-p/634286#M220341</guid>
      <dc:creator>lennys26</dc:creator>
      <dc:date>2023-03-13T15:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: TSTATS using a lookup table for a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/TSTATS-using-a-lookup-table-for-a-variable/m-p/634294#M220344</link>
      <description>&lt;P&gt;Neither of these are quite the same as&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;&amp;nbsp;and I showed. The subsearch needs to be inserted so that it is part of the where clause&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats count as count where index="titan" sourcetype="titan:cdr*" ROUTING_CDN!=BA* REL_CAUSE=* [| inputlookup lookuptable.csv 
  | sort 10 -dm
  | head 1 
  | rename oper as id
  | fields id
  | format ] ...&lt;/LI-CODE&gt;&lt;P&gt;The format command effectively expands the rows and fields into an expression like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;( ( fieldA="Row 1" AND fieldB="Row 1" ) OR ( fieldA="Row 2" AND fieldB="Row 2" ) OR ( fieldA="Row 3" AND fieldB="Row 3" ) OR ( fieldA="Row 4" AND fieldB="Row 4" ) OR ( fieldA="Row 5" AND fieldB="Row 5" ) )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 15:35:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/TSTATS-using-a-lookup-table-for-a-variable/m-p/634294#M220344</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-03-13T15:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: TSTATS using a lookup table for a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/TSTATS-using-a-lookup-table-for-a-variable/m-p/634295#M220345</link>
      <description>&lt;P&gt;If the field name in the subsearch doesn't match that in the index then the &lt;FONT face="courier new,courier"&gt;return&lt;/FONT&gt; command can be used to create an alias.&amp;nbsp; See my modified answer.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 15:37:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/TSTATS-using-a-lookup-table-for-a-variable/m-p/634295#M220345</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-03-13T15:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: TSTATS using a lookup table for a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/TSTATS-using-a-lookup-table-for-a-variable/m-p/634378#M220377</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;. Karma to you both.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 10:46:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/TSTATS-using-a-lookup-table-for-a-variable/m-p/634378#M220377</guid>
      <dc:creator>lennys26</dc:creator>
      <dc:date>2023-03-14T10:46:08Z</dc:date>
    </item>
  </channel>
</rss>

