<?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: Trying to get total count till selected year from multiselect input in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-total-count-till-selected-year-from-multiselect/m-p/475259#M192551</link>
    <description>&lt;P&gt;@piyali_sarkar,&lt;/P&gt;

&lt;P&gt;Not sure why you have a &lt;CODE&gt;multiselect&lt;/CODE&gt; instead of a simple dropdown because you want the count until the lowest/highest value of year from the selected year values.&lt;/P&gt;

&lt;P&gt;Nevertheless, you can find the &lt;CODE&gt;min&lt;/CODE&gt; or &lt;CODE&gt;max&lt;/CODE&gt; from the selected years and substitute that value in your &lt;CODE&gt;eval&lt;/CODE&gt; function&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Use &lt;CODE&gt;,&lt;/CODE&gt; as delimiter in your multiselect&lt;/LI&gt;
&lt;LI&gt;Change the eval to &lt;CODE&gt;| eval cur_year=tonumber(min($year_value$) )&lt;/CODE&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Here is a run anywhere example&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form&amp;gt;
  &amp;lt;fieldset submitButton="false"&amp;gt;
    &amp;lt;input type="multiselect" token="field1"&amp;gt;
      &amp;lt;label&amp;gt;field1&amp;lt;/label&amp;gt;
      &amp;lt;choice value="2019"&amp;gt;2019&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="2018"&amp;gt;2018&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="2017"&amp;gt;2017&amp;lt;/choice&amp;gt;
      &amp;lt;default&amp;gt;2019&amp;lt;/default&amp;gt;
      &amp;lt;initialValue&amp;gt;2019&amp;lt;/initialValue&amp;gt;
      &amp;lt;delimiter&amp;gt;,&amp;lt;/delimiter&amp;gt;
    &amp;lt;/input&amp;gt;
  &amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| makeresults| eval year="2019"| eval Status=if (year &amp;gt; tonumber(min($field1$)),1,0)&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-15m&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 11 Sep 2019 09:07:27 GMT</pubDate>
    <dc:creator>renjith_nair</dc:creator>
    <dc:date>2019-09-11T09:07:27Z</dc:date>
    <item>
      <title>Trying to get total count till selected year from multiselect input</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-total-count-till-selected-year-from-multiselect/m-p/475258#M192550</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;I am trying to display total active users count till selected year.&lt;BR /&gt;
I could achieve this , if I select only one year at a time, but if i try to select more that 1 year , I am getting error .&lt;/P&gt;

&lt;H2&gt;Query using :&lt;/H2&gt;

&lt;P&gt;base query&lt;BR /&gt;
| eval cur_year=tonumber($year_value$)  --&amp;gt; this is not allowing me to select more than one year.&lt;BR /&gt;
| eval count_status=if(Status="Active" AND year &amp;lt;= cur_year,1,0)&lt;BR /&gt;
| stats sum(count_status) as count_status by Supplier&lt;/P&gt;

&lt;P&gt;Could anyone please let me know if there is a way to display total count till multiple years.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:06:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-total-count-till-selected-year-from-multiselect/m-p/475258#M192550</guid>
      <dc:creator>piyali_sarkar</dc:creator>
      <dc:date>2020-09-30T02:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get total count till selected year from multiselect input</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-total-count-till-selected-year-from-multiselect/m-p/475259#M192551</link>
      <description>&lt;P&gt;@piyali_sarkar,&lt;/P&gt;

&lt;P&gt;Not sure why you have a &lt;CODE&gt;multiselect&lt;/CODE&gt; instead of a simple dropdown because you want the count until the lowest/highest value of year from the selected year values.&lt;/P&gt;

&lt;P&gt;Nevertheless, you can find the &lt;CODE&gt;min&lt;/CODE&gt; or &lt;CODE&gt;max&lt;/CODE&gt; from the selected years and substitute that value in your &lt;CODE&gt;eval&lt;/CODE&gt; function&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Use &lt;CODE&gt;,&lt;/CODE&gt; as delimiter in your multiselect&lt;/LI&gt;
&lt;LI&gt;Change the eval to &lt;CODE&gt;| eval cur_year=tonumber(min($year_value$) )&lt;/CODE&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Here is a run anywhere example&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form&amp;gt;
  &amp;lt;fieldset submitButton="false"&amp;gt;
    &amp;lt;input type="multiselect" token="field1"&amp;gt;
      &amp;lt;label&amp;gt;field1&amp;lt;/label&amp;gt;
      &amp;lt;choice value="2019"&amp;gt;2019&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="2018"&amp;gt;2018&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="2017"&amp;gt;2017&amp;lt;/choice&amp;gt;
      &amp;lt;default&amp;gt;2019&amp;lt;/default&amp;gt;
      &amp;lt;initialValue&amp;gt;2019&amp;lt;/initialValue&amp;gt;
      &amp;lt;delimiter&amp;gt;,&amp;lt;/delimiter&amp;gt;
    &amp;lt;/input&amp;gt;
  &amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| makeresults| eval year="2019"| eval Status=if (year &amp;gt; tonumber(min($field1$)),1,0)&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-15m&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Sep 2019 09:07:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-total-count-till-selected-year-from-multiselect/m-p/475259#M192551</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2019-09-11T09:07:27Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get total count till selected year from multiselect input</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-total-count-till-selected-year-from-multiselect/m-p/475260#M192552</link>
      <description>&lt;P&gt;Hi Renjith,&lt;/P&gt;

&lt;P&gt;Thank you for your response. Apology if I was not clear enough.&lt;BR /&gt;
I don't want to get the min or Max value , I will try to explain the query below:&lt;BR /&gt;
1.base query &amp;gt;&amp;gt; In my base query , there are fields like, &lt;BR /&gt;
  Status (Active/Inactive),&lt;BR /&gt;
  Supplier (FALSE/TRUE) , &lt;BR /&gt;
  Originated date (I am extracting year from this field)&lt;BR /&gt;
2. I have dynamic query to generate the year from the indexed data,&lt;BR /&gt;
    | eval count_status=if(Status="Active" AND year &amp;lt;= cur_year,1,0) &lt;BR /&gt;
     in the above line , "cur_year" value if the year field token value , so this &lt;BR /&gt;
     query is calculating total "ACTIVE" users from start to the year selected.&lt;/P&gt;

&lt;P&gt;My problem here is , when I selecting one year for ex. 2016 ,the query is displaying total active user count till 2016 from starting , but if I select 2016 as well as 2018, the eval command is throwing error.&lt;BR /&gt;
So I want to display total active users till 2016 as well as 2018&lt;BR /&gt;
Is it possible ?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:06:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-total-count-till-selected-year-from-multiselect/m-p/475260#M192552</guid>
      <dc:creator>piyali_sarkar</dc:creator>
      <dc:date>2020-09-30T02:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get total count till selected year from multiselect input</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-total-count-till-selected-year-from-multiselect/m-p/475261#M192553</link>
      <description>&lt;P&gt;@piyali_sarkar, &lt;BR /&gt;
Sorry but what do you mean by " I want to display total active users till 2016 as well as 2018" ?&lt;BR /&gt;
Because when you select 2018 , it includes both 2016,2017 and 2018&lt;BR /&gt;
Do you want count by the year ? &lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 12:17:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-total-count-till-selected-year-from-multiselect/m-p/475261#M192553</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2019-09-11T12:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get total count till selected year from multiselect input</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-total-count-till-selected-year-from-multiselect/m-p/475262#M192554</link>
      <description>&lt;P&gt;yes, Actually if you see my query , I am calculating total active user count till 2016 , So If I want display the count till 2016 and then till 2018 , just to see the diff between the total active user count of these two years, Is it possible in one query ?&lt;BR /&gt;
Suppose in 2016 total active user count is 3K and in 2018 it's 6K&lt;BR /&gt;
Can I display both counts using one query ? &lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 12:37:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-total-count-till-selected-year-from-multiselect/m-p/475262#M192554</guid>
      <dc:creator>piyali_sarkar</dc:creator>
      <dc:date>2019-09-11T12:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get total count till selected year from multiselect input</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-total-count-till-selected-year-from-multiselect/m-p/475263#M192555</link>
      <description>&lt;P&gt;So, if you are trying to find the sum of values for the given years you'll need to get pretty creative. The way I read your question means you want results for each of the years selected, so if they pick 2018 and 2019 then you'll have two results.&lt;/P&gt;

&lt;P&gt;Here is something that runs against the main index, the top section you would have to fix for using your Multi-Select. Should work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval firstDay= "09/09/2019"
| eval secondDay= "09/10/2019"
| eval thirdDay="09/11/2019"
| eval daysCombined = firstDay.",".secondDay.",".thirdDay 
| makemv daysCombined delim="," 
| fields daysCombined 
| eval groupBy="foo" 
| append 
    [| tstats count where index=main earliest=-3d@d by _time span=1d 
    | eval formattedTime = strftime(_time, "%m/%d/%Y") 
    | eval groupBy="foo" 
    | eval {formattedTime}Count = count 
    | stats first(*Count) as *Count by groupBy
        ] 
| stats list(*) as * by groupBy
| mvexpand daysCombined
| foreach *Count [eval &amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;Included = if(strptime("&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;", "%m/%d/%Y") &amp;gt;= strptime(daysCombined, "%m/%d/%Y"), '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', 0)]
| stats sum(*Included) as *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Enjoy!!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 19:59:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-total-count-till-selected-year-from-multiselect/m-p/475263#M192555</guid>
      <dc:creator>tjago11</dc:creator>
      <dc:date>2019-09-11T19:59:18Z</dc:date>
    </item>
  </channel>
</rss>

