<?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: Build a query by last date in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-build-a-query-by-last-date/m-p/586175#M204191</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/243317"&gt;@Maik11&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;let me understand:&lt;/P&gt;&lt;P&gt;you extracted two fields (&lt;SPAN&gt;crdate and&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;upddate) that are the creation and update dates of an object called "belegnummer".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You want to know if there are more than one "update" for each&amp;nbsp;belegnummer, is it correct?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if this is your need, you have to run something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=your_index belegnummer=177287
| eval crdate_epoch=strptime(crdate,"%Y-%m-%d")
| eval upddate_epoch=strptime(upddate,"%Y-%m-%d")
| stats dc(update_epoch) AS dc_update_epoch last(upddate) by belegnummer
| where dc_update_epoch&amp;gt;1&lt;/LI-CODE&gt;&lt;P&gt;See my approach and adapt it to you need.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
    <pubDate>Wed, 23 Feb 2022 09:24:30 GMT</pubDate>
    <dc:creator>gcusello</dc:creator>
    <dc:date>2022-02-23T09:24:30Z</dc:date>
    <item>
      <title>How to build a query by last date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-build-a-query-by-last-date/m-p/586172#M204190</link>
      <description>&lt;P&gt;Hello All,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need some help please.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to query for the last upddate.&amp;nbsp; However, the field belegtyp and pdid can also change.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need the last upddate for them all ( last upddate when belegtyp for pdid change).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thats my query:&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| eval crdate=strptime(crdate,"%Y-%m-%d")
| eval crdate=strftime(crdate,"%Y-%m-%d")
| eval upddate=strptime(upddate,"%Y-%m-%d")
| eval upddate=strftime(upddate,"%Y-%m-%d")
| search belegnummer=177287
| stats last(upddate) by upddate crdate belegnummer belegtyp pdid&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It hasn´t work so far with&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| sort -upddate  

| stats last (upddate) by ...

| stats first (upddate) by...&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know why it doesn't work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Hope to get some help on this, thanks in advance.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 16:39:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-build-a-query-by-last-date/m-p/586172#M204190</guid>
      <dc:creator>Maik11</dc:creator>
      <dc:date>2022-02-23T16:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: Build a query by last date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-build-a-query-by-last-date/m-p/586175#M204191</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/243317"&gt;@Maik11&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;let me understand:&lt;/P&gt;&lt;P&gt;you extracted two fields (&lt;SPAN&gt;crdate and&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;upddate) that are the creation and update dates of an object called "belegnummer".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You want to know if there are more than one "update" for each&amp;nbsp;belegnummer, is it correct?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if this is your need, you have to run something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=your_index belegnummer=177287
| eval crdate_epoch=strptime(crdate,"%Y-%m-%d")
| eval upddate_epoch=strptime(upddate,"%Y-%m-%d")
| stats dc(update_epoch) AS dc_update_epoch last(upddate) by belegnummer
| where dc_update_epoch&amp;gt;1&lt;/LI-CODE&gt;&lt;P&gt;See my approach and adapt it to you need.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 09:24:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-build-a-query-by-last-date/m-p/586175#M204191</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-02-23T09:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Build a query by last date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-build-a-query-by-last-date/m-p/586176#M204192</link>
      <description>&lt;P&gt;Does this get you what you want?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats latest(belegtyp) as belegtyp latest(pdid) as pdid by belegnummer&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 23 Feb 2022 09:30:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-build-a-query-by-last-date/m-p/586176#M204192</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-02-23T09:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: Build a query by last date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-build-a-query-by-last-date/m-p/586180#M204193</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;thanks for your help. But your suggestions&amp;nbsp; unfortunately don't work too.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have several updates where the belegtyp of one or more pdid can change.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my example it is just one belegnummer. Usually these are thousands belegnummer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need the last update on which the belegtyp from pdid of the belegnummer changes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because the belegtyp can change between 1 to 10 .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 09:44:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-build-a-query-by-last-date/m-p/586180#M204193</guid>
      <dc:creator>Maik11</dc:creator>
      <dc:date>2022-02-23T09:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: Build a query by last date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-build-a-query-by-last-date/m-p/586181#M204194</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/243317"&gt;@Maik11&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;you have to enlarge your stats command:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=your_index belegnummer=177287
| eval crdate_epoch=strptime(crdate,"%Y-%m-%d")
| eval upddate_epoch=strptime(upddate,"%Y-%m-%d")
| stats dc(belegtyp) AS dc_belegtyp last(upddate) by pid belegnummer
| where dc_belegtyp&amp;gt;1&lt;/LI-CODE&gt;&lt;P&gt;Anyway, try to apply my approach to your Use Case, it's the best way to learn!&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 09:48:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-build-a-query-by-last-date/m-p/586181#M204194</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-02-23T09:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Build a query by last date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-build-a-query-by-last-date/m-p/586206#M204198</link>
      <description>&lt;P&gt;Hi Guiseppe,&lt;/P&gt;
&lt;P&gt;I understand your suggestions. But it only counts me which pdid and belegnummer has more than one belegtyp.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Maik11_0-1645613420933.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/18092i2D239A3681BBE552/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Maik11_0-1645613420933.png" alt="Maik11_0-1645613420933.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;In this example I get this back.&lt;/P&gt;
&lt;P&gt;But I need back, from ZX5165 = belegtyp 6 (second) and from ZX5166, ZX5167 and ZX5168 = belegtyp=7.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is the last change of the update in my query.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 16:38:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-build-a-query-by-last-date/m-p/586206#M204198</guid>
      <dc:creator>Maik11</dc:creator>
      <dc:date>2022-02-23T16:38:16Z</dc:date>
    </item>
  </channel>
</rss>

