<?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 compare last value with the 7th last value? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-last-value-with-the-7th-last-value/m-p/639455#M221558</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;How to compare last value with the second last value?&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;....&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;I want to compare the last record 80 with that of 67( last value and want to write whether the value was 'greater' or 'smaller' in the output.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P class="lia-align-left"&gt;In above case 55 was greater so my output should say GREATER. ...&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;You may need to describe the use case with consistency. &amp;nbsp;The title says last vs 7th last, which kinda agrees with 80 vs 67. &amp;nbsp;Then, the opening sentence says last with second last; and the last sentence cites a number 55 which is neither the 7th last nor the second last.&lt;/P&gt;&lt;P&gt;Here, I'll take 7th last. &amp;nbsp;The following statement also needs clarification:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;Say I have a column with N records in it&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Does this mean that the column is multivalued with 7 records, or does it mean that you have 7 separate events with this column?&lt;/P&gt;&lt;P&gt;If former, a semantical interpretation of your requirement (compare with 7th last) is&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval output = if(tonumber(mvindex(column, -1)) - tonumber(mvindex(column, -7)) &amp;gt; 0, "GREATER", "SMALLER or EQUAL")&lt;/LI-CODE&gt;&lt;P&gt;If latter, you first make the column multivalued with original sequence.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats list(column) as column
| eval output = if(tonumber(mvindex(column, -1)) - tonumber(mvindex(column, -7)) &amp;gt; 0, "GREATER", "SMALLER or EQUAL")&lt;/LI-CODE&gt;&lt;P&gt;Here, I also do not know if you want EQUAL to be a separate output so I'm using the simplest if() function. &amp;nbsp;If you need a separate EQUAL, it would be more economic to save output of mvindex to variables (fields) before applying case() command.&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
    <pubDate>Tue, 11 Apr 2023 06:57:32 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2023-04-11T06:57:32Z</dc:date>
    <item>
      <title>How to compare last value with the 7th last value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-last-value-with-the-7th-last-value/m-p/639440#M221553</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;How to compare last value with the second last value?&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;Say I have a column with N records in it&lt;BR /&gt;88&lt;BR /&gt;22&lt;BR /&gt;67. --&amp;gt;&lt;BR /&gt;44&lt;BR /&gt;55&lt;BR /&gt;12&lt;BR /&gt;44&lt;BR /&gt;75&lt;BR /&gt;80 --&amp;gt;&lt;/P&gt;&lt;P&gt;I want to compare the last record 80 with that of 67( last value and want to write whether the value was 'greater' or 'smaller' in the output.&lt;/P&gt;&lt;P class="lia-align-left"&gt;In above case 55 was greater so my output should say GREATER. Do we have any command to accomplish this?&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 11 Apr 2023 01:44:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-last-value-with-the-7th-last-value/m-p/639440#M221553</guid>
      <dc:creator>aguasd12</dc:creator>
      <dc:date>2023-04-11T01:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare last value with the 7th last value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-last-value-with-the-7th-last-value/m-p/639442#M221554</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/255718"&gt;@aguasd12&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;An interesting use case.&amp;nbsp; Something like this should work...&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval n=mvrange(0,80)
| mvexpand n
| eval n=substr(tostring(n * random()), 1, 2)
  ``` above just creates dummy results ```
  ``` add the following to you query ```
| streamstats count
| where count=67 OR count=80
| table count n
| transpose header_field="count"
| eval status=case(('67'=='80'), "EQUAL", ('67' &amp;gt; '80'), "GREATER THAN", ('67' &amp;lt; '80'), "LESS THAN")&lt;/LI-CODE&gt;&lt;P&gt;Hope that helps&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2023 03:27:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-last-value-with-the-7th-last-value/m-p/639442#M221554</guid>
      <dc:creator>yeahnah</dc:creator>
      <dc:date>2023-04-11T03:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare last value with the 7th last value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-last-value-with-the-7th-last-value/m-p/639443#M221555</link>
      <description>&lt;P&gt;On rereading your question I see I misunderstood it, initially.&amp;nbsp; This should meet you use case&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval n=mvrange(0,100)
| mvexpand n
| eval n=substr(tostring(n * random()), 1, 2)
  ``` above just creates dummy results ```
  ``` add the following to your query ```
| streamstats count
| eventstats max(count) as total_rows
| eval 7thlast=(total_rows-7)
| where count='7thlast' OR count='total_rows'
| table count n 7thlast total_rows
| transpose
| where column="n"
| rename "row 1" AS 7thlast, "row 2" AS last
| eval status=case(('7thlast'=='last'), "EQUAL", ('7thlast' &amp;gt; 'last'), "GREATER THAN", ('7thlast' &amp;lt; 'last'), "LESS THAN")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2023 04:12:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-last-value-with-the-7th-last-value/m-p/639443#M221555</guid>
      <dc:creator>yeahnah</dc:creator>
      <dc:date>2023-04-11T04:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare last value with the 7th last value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-last-value-with-the-7th-last-value/m-p/639455#M221558</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;How to compare last value with the second last value?&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;....&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;I want to compare the last record 80 with that of 67( last value and want to write whether the value was 'greater' or 'smaller' in the output.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P class="lia-align-left"&gt;In above case 55 was greater so my output should say GREATER. ...&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;You may need to describe the use case with consistency. &amp;nbsp;The title says last vs 7th last, which kinda agrees with 80 vs 67. &amp;nbsp;Then, the opening sentence says last with second last; and the last sentence cites a number 55 which is neither the 7th last nor the second last.&lt;/P&gt;&lt;P&gt;Here, I'll take 7th last. &amp;nbsp;The following statement also needs clarification:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;Say I have a column with N records in it&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Does this mean that the column is multivalued with 7 records, or does it mean that you have 7 separate events with this column?&lt;/P&gt;&lt;P&gt;If former, a semantical interpretation of your requirement (compare with 7th last) is&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval output = if(tonumber(mvindex(column, -1)) - tonumber(mvindex(column, -7)) &amp;gt; 0, "GREATER", "SMALLER or EQUAL")&lt;/LI-CODE&gt;&lt;P&gt;If latter, you first make the column multivalued with original sequence.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats list(column) as column
| eval output = if(tonumber(mvindex(column, -1)) - tonumber(mvindex(column, -7)) &amp;gt; 0, "GREATER", "SMALLER or EQUAL")&lt;/LI-CODE&gt;&lt;P&gt;Here, I also do not know if you want EQUAL to be a separate output so I'm using the simplest if() function. &amp;nbsp;If you need a separate EQUAL, it would be more economic to save output of mvindex to variables (fields) before applying case() command.&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2023 06:57:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-last-value-with-the-7th-last-value/m-p/639455#M221558</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-04-11T06:57:32Z</dc:date>
    </item>
  </channel>
</rss>

