<?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: How to edit my search to create a weekly trend chart for our data? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250394#M74783</link>
    <description>&lt;P&gt;Thanks Somesh again for your answer. The output(dates) are as expected now . But we still have an issue here.The source data files referred for calculation in each of the last three weeks is incorrect. Given that data is available for all days in the last three weeks , we need latest source file for that particular week to be  used .&lt;/P&gt;

&lt;P&gt;Here is the source data file that is presently been referred For following weeks  :&lt;BR /&gt;
June 19th-June 25 : Source file referred is data of 22nd June&lt;BR /&gt;
June 26th -July 2 :    Source file referred is data of 29th June&lt;BR /&gt;
July3 -July 9 :            Source file referred is data of 4th July &lt;/P&gt;

&lt;P&gt;It should have referred and used  the source data file of June 25,July 2nd  and July 9th as we have data for all these days.Do you see an issue with above TSTATS command. Please let me know.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jul 2016 10:51:49 GMT</pubDate>
    <dc:creator>amoldesai</dc:creator>
    <dc:date>2016-07-13T10:51:49Z</dc:date>
    <item>
      <title>How to edit my search to create a weekly trend chart for our data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250389#M74778</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;We have  the following requirement for a weekly trend chart for the data that we get on daily basis (mostly).&lt;/P&gt;

&lt;P&gt;1) We need to show end of the weekly period date for labels (Week range is from Sunday to Saturday). That is , we need to have Saturday's date on the label for each historical point &lt;BR /&gt;
But if today we are on Wednesday, then for the current week, we show Wednesday data as well as Wednesday's date on the label.&lt;/P&gt;

&lt;P&gt;2) We need to use the latest data for that week. I have a solution for this using tstats as in the example search below.&lt;/P&gt;

&lt;P&gt;To elaborate with an example, consider we receive data on daily basis for the last 3 weeks till today (July &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt; .&lt;/P&gt;

&lt;P&gt;Following will be the labels on the chart (ignore the format of date): 18th June, 25th of June, 2nd of July and 8th of July. 8th July is considered since it is the latest in this week.&lt;/P&gt;

&lt;P&gt;3) Data to be considered for the 18th June label will be the latest data received between 12th June to 18th June and so on for other dates.&lt;/P&gt;

&lt;P&gt;I tried using the following search, but it does not give expected results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index ="xyz"   earliest=-3w@w6  latest=now sourcetype = cache-v2  [| tstats max(_time) as maxTime WHERE index=xyz source="*xyz_details*" by source _time span=1w | sort -maxTime | stats first(source) as source by _time | fields source]   |   eval Time=_time  | timechart  span=1w dc(psirtColdId)   by matchConfidence |  eval Time=strftime(_time,"%Y:%m:%d") | table Time,"Potentially Vulnerable",Vulnerable
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please let me know how this can be achieved.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;-Amol&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2016 18:38:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250389#M74778</guid>
      <dc:creator>amoldesai</dc:creator>
      <dc:date>2016-07-08T18:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to create a weekly trend chart for our data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250390#M74779</link>
      <description>&lt;P&gt;How about this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index ="xyz"   earliest=-3w@w6  latest=now sourcetype = cache-v2  [| tstats max(_time) as maxTime WHERE index=xyz source="*xyz_details*" by source _time span=1w | sort -maxTime | stats first(source) as source by _time | fields source]   |   eval Time=_time  | timechart  span=1w dc(psirtColdId)   by matchConfidence  |  eval _time=if(_time=relative_time(now(),"@w"), relative_time(now(),"@d"),_time + (86400*7))  |  eval Time=strftime(_time,"%Y:%m:%d") | table Time,"Potentially Vulnerable",Vulnerable
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also, when you say you don't get the expected result from your search, could you explain what is wrong with the output?&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;UPdated&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index ="xyz"   earliest=-3w@w6  latest=now sourcetype = cache-v2  [| tstats max(_time) as maxTime WHERE index=xyz source="*xyz_details*" by source _time span=1w | sort -maxTime | stats first(source) as source by _time | fields source]   | timechart  span=1w dc(psirtColdId)   by matchConfidence  |  eval _time=_time + (86400*7) | eval _time=if(_time&amp;gt;now(),elative_time(now(),"@d"),_time) |  eval Time=strftime(_time,"%Y:%m:%d") | table Time,"Potentially Vulnerable",Vulnerable
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Jul 2016 21:36:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250390#M74779</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-07-08T21:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to create a weekly trend chart for our data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250391#M74780</link>
      <description>&lt;P&gt;I do not understand, will you please elaborate on your 3-weeks example?&lt;/P&gt;

&lt;P&gt;What &lt;EM&gt;EXACTLY&lt;/EM&gt; should be the output (give a mockup)?&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jul 2016 03:32:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250391#M74780</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-07-09T03:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to create a weekly trend chart for our data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250392#M74781</link>
      <description>&lt;P&gt;Thanks  Somesh for your answer .  Somesh/Gregg, here is the output that I get for data uploaded for last 3 weeks  till yesterday (11 July) using the above query provided by Somesh&lt;/P&gt;

&lt;P&gt;2016:06:25  87  89&lt;BR /&gt;
2016:07:02  87  89&lt;BR /&gt;
2016:07:09  88  89&lt;BR /&gt;
&lt;STRONG&gt;2016:07:16&lt;/STRONG&gt;    90  89.&lt;/P&gt;

&lt;P&gt;The last date is the problem here.  I want the last date to be the date of the last upload data(11 July) and not end of the current week (16th July). The output I need should be as follows :&lt;/P&gt;

&lt;P&gt;2016:06:25  87  89&lt;BR /&gt;
2016:07:02  87  89&lt;BR /&gt;
2016:07:09  88  89&lt;BR /&gt;
&lt;STRONG&gt;2016:07:11&lt;/STRONG&gt;    90  89.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 18:20:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250392#M74781</guid>
      <dc:creator>amoldesai</dc:creator>
      <dc:date>2016-07-12T18:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to create a weekly trend chart for our data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250393#M74782</link>
      <description>&lt;P&gt;Try the updated answer&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 18:47:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250393#M74782</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-07-12T18:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to create a weekly trend chart for our data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250394#M74783</link>
      <description>&lt;P&gt;Thanks Somesh again for your answer. The output(dates) are as expected now . But we still have an issue here.The source data files referred for calculation in each of the last three weeks is incorrect. Given that data is available for all days in the last three weeks , we need latest source file for that particular week to be  used .&lt;/P&gt;

&lt;P&gt;Here is the source data file that is presently been referred For following weeks  :&lt;BR /&gt;
June 19th-June 25 : Source file referred is data of 22nd June&lt;BR /&gt;
June 26th -July 2 :    Source file referred is data of 29th June&lt;BR /&gt;
July3 -July 9 :            Source file referred is data of 4th July &lt;/P&gt;

&lt;P&gt;It should have referred and used  the source data file of June 25,July 2nd  and July 9th as we have data for all these days.Do you see an issue with above TSTATS command. Please let me know.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 10:51:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250394#M74783</guid>
      <dc:creator>amoldesai</dc:creator>
      <dc:date>2016-07-13T10:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to create a weekly trend chart for our data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250395#M74784</link>
      <description>&lt;P&gt;Try the tstats subsearch below (just run as independent search) and see if it gives correct source&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats max(_time) as maxTime WHERE index=xyz source="*xyz_details*" by source _time span=1w | sort -maxTime | dedup _time | fields source
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also, could you provide some sample source values, how they are formatted?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 14:57:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250395#M74784</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-07-13T14:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to create a weekly trend chart for our data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250396#M74785</link>
      <description>&lt;P&gt;Hi Somesh,&lt;/P&gt;

&lt;P&gt;Here is the output of the above command:&lt;/P&gt;

&lt;P&gt;source                                                               _time&lt;BR /&gt;
/793491/psirt_details.2016071301.gz      2016-07-07&lt;BR /&gt;
/793491/psirt_details.2016070401.gz      2016-06-30&lt;BR /&gt;
/793491/psirt_details.2016062901.gz      2016-06-23&lt;BR /&gt;
/793491/psirt_details.2016062202.gz           2016-06-16&lt;/P&gt;

&lt;P&gt;Please note the file name contains  the data generated date.&lt;BR /&gt;
eg:  psirt_details.2016071301.gz  data file name represents data  on  13th of July,2016, the last two digits are insignificant.&lt;/P&gt;

&lt;P&gt;If you see the span of 1w considered in the above query, it is relative to todays date. It should be from "Sunday" to "Saturday" (details of week range in my first post). For instance, for the week range (July 3 to      July 9), July 9 should be one of the data point(label in the chart) and the source to be considered for this week should be July 9th (the latest one which ever for that week). &lt;/P&gt;

&lt;P&gt;Thanks again for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 10:12:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250396#M74785</guid>
      <dc:creator>amoldesai</dc:creator>
      <dc:date>2020-09-29T10:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to create a weekly trend chart for our data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250397#M74786</link>
      <description>&lt;P&gt;Hi Somesh,&lt;/P&gt;

&lt;P&gt;After adding &lt;CODE&gt;earliest=-3w@w7&lt;/CODE&gt; in the &lt;CODE&gt;WHERE&lt;/CODE&gt; clause of  tstats command, I got the expected result. Here is the complete query for a) Having week range from Sunday to Saturday a) Using the latest source of that week c) For the current week, it considers the latest data  source and its date:&lt;/P&gt;

&lt;P&gt;index ="XYZ" earliest=-12w@w6 latest=now sourcetype = v2  source="&lt;EM&gt;XYZ&lt;/EM&gt;"&lt;BR /&gt;
 [| tstats max(_time) as maxTime WHERE index=XYZ &lt;STRONG&gt;earliest=-12w@w7&lt;/STRONG&gt; source="&lt;EM&gt;XYZ&lt;/EM&gt;" by source _time span=1w | rex field=source "/(?\d+\/\w+).\d+"| sort -maxTime | stats first(source) as source by _time | fields source] | timechart  span=1w dc(Id)   by matchConfidence  |  eval _time=_time + (86400*7) | eval _time=if(_time&amp;gt;now(),relative_time(now(),"@d"),_time) |  eval Time=strftime(_time,"%Y:%m:%d") | table Time,"Potentially Vulnerable",Vulnerable&lt;/P&gt;

&lt;P&gt;Thanks a lot Somesh for all your help here. Really appreciate it.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 10:15:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-create-a-weekly-trend-chart-for-our/m-p/250397#M74786</guid>
      <dc:creator>amoldesai</dc:creator>
      <dc:date>2020-09-29T10:15:24Z</dc:date>
    </item>
  </channel>
</rss>

