Dashboards & Visualizations

set time range token with multiselect input

Zero
Engager

I have a mutiselect input like this

 

<input type="multiselect" token="year">
<label>Year</label>
<choice value="*">All</choice>
<delimiter> OR year=</delimiter>
<fieldForLabel>year</fieldForLabel>
<fieldForValue>year</fieldForValue>
<search>
<query>| inputlookup supported_years.csv
| dedup year
| table year</query>
</search>
<default>2023</default>
<initialValue>2023</initialValue>
</input>

 



I want to set the time range token to the result of the input selection above. If 2023 was chosen, the token value for $timeRangeEarliest$ should be 2023/01/01 and the token value for $timeRangeLastet$ should be 2023/12/31.  If 2021 and 2023 was chosen, the token value for $timeRangeEarliest$ should be 2021/01/01 and the token value for $timeRangeLastet$ should be 2023/12/31. Etc.

I want to use this two tokens for time range in search. Don't know how to do it. Please help. Many thanks.

Labels (2)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Your question is a little confusing. You have mentioned the same token twice. Also, please can you clarify what you want if three different years are chosen? Also, how are you going to use the token(s) as this makes a difference to how they might be set up?

0 Karma

Zero
Engager

Thanks for your reply.

Sorry for the two identical token name, this was a typo and I have corrected it.

If there are three or more years, I want to find the earliest year and the latest year, and use the date as tokens. (I just want to find the smallest time range that covers all those years.) And I want to use the tokens for time range of searches in dashboard. Like this:

<search>
<query>| index=abc</query>
<earliest>$timeRangeEarliest$</earliest>
<latest>$timeRangeLastet$</latest>
</search>
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this - note that is doesn't deal with All - for that (should you decide it is necessary), you would have to do something a bit more complicated

<input type="multiselect" token="year">
<label>Year</label>
<fieldForLabel>year</fieldForLabel>
<fieldForValue>year</fieldForValue>
<search>
<query>| inputlookup supported_years.csv
| dedup year
| table year</query>
</search>
<default>2023</default>
<initialValue>2023</initialValue>
      <change>
        <eval token="earliest">mvindex(mvsort($form.year$),0)</eval>
        <eval token="latest">mvindex(mvsort($form.year$),mvcount($form.year$)-1)</eval>
        <eval token="timeRangeEarliest">strptime($earliest$."0101","%Y%m%d")</eval>
        <eval token="timeRangeLatest">relative_time(strptime(($latest$)."0101","%Y%m%d"),"+1y")</eval>
      </change>
</input>
0 Karma
Get Updates on the Splunk Community!

Application management with Targeted Application Install for Victoria Experience

  Experience a new era of flexibility in managing your Splunk Cloud Platform apps! With Targeted Application ...

Index This | What goes up and never comes down?

January 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Splunkers, Pack Your Bags: Why Cisco Live EMEA is Your Next Big Destination

The Power of Two: Splunk &#43; Cisco at "Ludicrous Scale"   You know Splunk. You know Cisco. But have you seen ...