Dashboards & Visualizations

How do I retrieve the first and last date from each month?

udaypulipaka
Observer

Hi,

I have two dropdowns (namely month and year). My query is to display results month wise. If I select January and 2018, then 1st to 31 jan 2018 data should be displayed. I am passing month and year tokens in query, but how do I retrieve the last date of each month?

Please help.

Tags (3)
0 Karma
1 Solution

vishaltaneja070
Motivator

Hello @udaypulipaka,

This query can help you

    |makeresults | eval time1="01-"."Jan"."-"."2019" | eval time1=strptime(time1,"%d-%b-%Y") | eval time2 = relative_time(time1, "+1mon") | eval time2 = relative_time(time2, "-1d") | eval time1=strftime(time1, "%d-%m-%Y") | eval time2=strftime(time2, "%d-%m-%Y")

View solution in original post

0 Karma

vishaltaneja070
Motivator

Hello @udaypulipaka,

This query can help you

    |makeresults | eval time1="01-"."Jan"."-"."2019" | eval time1=strptime(time1,"%d-%b-%Y") | eval time2 = relative_time(time1, "+1mon") | eval time2 = relative_time(time2, "-1d") | eval time1=strftime(time1, "%d-%m-%Y") | eval time2=strftime(time2, "%d-%m-%Y")
0 Karma

udaypulipaka
Observer

Thank u so much.It's working fine

0 Karma

vishaltaneja070
Motivator

Great. your welcome 🙂

0 Karma

vishaltaneja070
Motivator

Updated the correct answer here as well:

 <form>
       <label>month&amp;year</label>
       <fieldset submitButton="false">
         <input type="dropdown" token="month_tok">
           <label>Month</label>
           <choice value="Jan">Jan</choice>
           <choice value="Feb">Feb</choice>
           <choice value="Mar">March</choice>
         </input>
         <input type="dropdown" token="year_tok">
           <label>Year</label>
           <choice value="2017">2017</choice>
           <choice value="2018">2018</choice>
           <choice value="2019">2019</choice>
         </input>
       </fieldset>
       <row>
         <panel>
           <title>$month_tok$     $year_tok$</title>
           <table>
             <search>
               <query>index="os" sourcetype="Ser" CaseNumber=* status=* assignment_group=*  [|makeresults | eval time1="01-".$month_tok|s$."-".$year_tok|s$ | eval time1=strptime(time1,"%d-%b-%Y") | eval time2 = relative_time(time1, "+1mon") | eval latest = relative_time(time2, "-1d") | eval earliest=time1 | return earliest, latest] |dedup _time,CaseNumber,assignment_group| streamstats current=f last(assignment_group) as lg, last(active) as Active by CaseNumber | eval ss=case(assignment_group!=lg AND assignment_group="Sus","Escalated",assignment_group="Sus" AND status="Complete" AND (isnull(Active) OR Active="true"),"Resolved") |stats count by ss</query>
               <earliest>-24h@h</earliest>
               <latest>now</latest>
             </search>
             <option name="drilldown">none</option>
             <option name="refresh.display">progressbar</option>
           </table>
         </panel>
       </row>
     </form>
0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...