Dashboards & Visualizations

How to add "Latest" keyword in the reporting day dropdown?

sai_krishna
Loves-to-Learn Lots

I want to add the "Latest" keyword to my drop down filter instead of date which displays the latest data.

Below is my source code:

 

 

<input type="dropdown" token="reportingDayA">
      <label>Reporting Day Misra apu</label>
      <fieldForLabel>readableDateA</fieldForLabel>
      <fieldForValue>epochA</fieldForValue>
      <search>
        <done>
          <set token="reportingDayDefA">$result.epochA$</set>
        </done>
        <query>index=`std_getAttrIndexBaseName`_qac$oem$ sourcetype=qac Variant="apu $Variant$"  Release=$release$ 
| dedup _time|  eval readableDateA=strftime(_time,"%F") 
| eval epochA=strftime(_time,"%s") | dedup readableDateA 
| sort - _time</query>
        <earliest>0</earliest>
        <latest></latest>
      </search>
      <default>$reportingDayDefA$</default>
    </input>

 

 

 

and Latest keyword should be default value to be selected

Labels (5)
0 Karma

danspav
SplunkTrust
SplunkTrust

Hi @sai_krishna,

Try this:

 <fieldset submitButton="false">
    <input type="dropdown" token="reportingDayA">
      <label>Reporting Day Misra apu</label>
      <fieldForLabel>readableDateA</fieldForLabel>
      <fieldForValue>epochA</fieldForValue>
      <search>
        <query>| tstats count where index=_internal by _time span=1d
| eval readableDateA=strftime(_time,"%F") 
| eval epochA=strftime(_time,"%s") | dedup readableDateA 
| sort - _time
``` get latest and call it "latest" ```
| eventstats max(epochA) as latest
| eval readableDateA=if(epochA=latest,"Latest",readableDateA)
</query>
        <earliest>-7d@d</earliest>
        <latest>now</latest>
      </search>
       <selectFirstChoice>true</selectFirstChoice>
    </input>
  </fieldset>

 

The search will get all the dates, and label the most recent one "Latest". 

Due to the way the list is sorted, this entry is the first one in the list.

We can use that to our advantage by using the selectFirstChoice option for the dropdown - that makes the
first entry in the list selected.

Here it is in a dashboard:

<form version="1.1" theme="light">
  <label>Answers</label>
  <fieldset submitButton="false">
    <input type="dropdown" token="reportingDayA">
      <label>Reporting Day Misra apu</label>
      <fieldForLabel>readableDateA</fieldForLabel>
      <fieldForValue>epochA</fieldForValue>
      <search>
        <query>| tstats count where index=_internal by _time span=1d
| eval readableDateA=strftime(_time,"%F") 
| eval epochA=strftime(_time,"%s") | dedup readableDateA 
| sort - _time
| eventstats max(epochA) as latest
| eval readableDateA=if(epochA=latest,"Latest",readableDateA)
</query>
        <earliest>-7d@d</earliest>
        <latest>now</latest>
      </search>
       <selectFirstChoice>true</selectFirstChoice>
    </input>
  </fieldset>
  <row>
  <html>
    <h1>You selected: $reportingDayA$</h1>
  </html>
  </row>
</form>


Cheers,
Daniel

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...