<?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 fields value with old fields value in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495060#M138032</link>
    <description>&lt;P&gt;you can use &lt;A href="https://docs.splunk.com/Documentation/SplunkCloud/latest/SearchReference/streamstats"&gt;streamstats&lt;/A&gt; &lt;/P&gt;

&lt;P&gt;something like &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;base search that gives a table of weekly information sorted properly&amp;gt;
|streamstats window=1 current=f values(*) as prev_* by _time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;may need to adjust label or sorting to have it make sense, though. &lt;/P&gt;</description>
    <pubDate>Thu, 10 Oct 2019 19:10:47 GMT</pubDate>
    <dc:creator>cmerriman</dc:creator>
    <dc:date>2019-10-10T19:10:47Z</dc:date>
    <item>
      <title>How to compare fields value with old fields value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495058#M138030</link>
      <description>&lt;P&gt;I am trying to make a search that will compare the fields value with the old fields value to determine if there is any change in the value over time or if there is a new field added. For example, say I have 5 fields | fields _time Location Band CellID CellName. I want to run this search and compare the these 5 fields data with a week old data of same fields. Say, Week 1 these fields show values as :&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;_time           Location    Band CellID  CellName&lt;BR /&gt;
2019-10-10 California  700   123       CELL123456-700-1&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Now I want to see if the last week the values were the same or different for same fields.&lt;BR /&gt;
Please help me to build the logic. Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 16:25:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495058#M138030</guid>
      <dc:creator>kulwindersandhu</dc:creator>
      <dc:date>2019-10-10T16:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields value with old fields value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495059#M138031</link>
      <description>&lt;P&gt;[insert normal search criteria here] | eval didItChange=(case(CellName != value, "Changed"))| stats latest(CellName) as CellName | table CellName, didItChange&lt;/P&gt;

&lt;P&gt;You can do this with the eval statement. Inside the eval, you can try using an if statement if you want instead of a case statement. If statements have acted wonky for me before.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.1/SearchReference/CommonEvalFunctions"&gt;https://docs.splunk.com/Documentation/Splunk/7.3.1/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.1/SearchReference/SearchTimeModifiers"&gt;https://docs.splunk.com/Documentation/Splunk/7.3.1/SearchReference/SearchTimeModifiers&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 19:02:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495059#M138031</guid>
      <dc:creator>rlippincott</dc:creator>
      <dc:date>2019-10-10T19:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields value with old fields value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495060#M138032</link>
      <description>&lt;P&gt;you can use &lt;A href="https://docs.splunk.com/Documentation/SplunkCloud/latest/SearchReference/streamstats"&gt;streamstats&lt;/A&gt; &lt;/P&gt;

&lt;P&gt;something like &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;base search that gives a table of weekly information sorted properly&amp;gt;
|streamstats window=1 current=f values(*) as prev_* by _time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;may need to adjust label or sorting to have it make sense, though. &lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 19:10:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495060#M138032</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2019-10-10T19:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields value with old fields value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495061#M138033</link>
      <description>&lt;P&gt;Greetings @kulwindersandhu,&lt;/P&gt;

&lt;P&gt;If you're ready to go for a ride, I've got a fancy search to display on one line all of the Active Directory fields that changed and the time of both the last change and the change before that.&lt;/P&gt;

&lt;P&gt;Base search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=active_directory
| table _time whenChanged Name Enabled LockedOut PasswordExpired
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Sample Base Data:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time                 whenChanged            Name     Enabled LockedOut PasswordExpired
2019-10-10 05:15:08 2019-10-10 02:15:08 evansj  false   true      false
2019-10-09 05:15:06 2019-10-09 03:15:06 evansj  true    false     false
2019-10-08 05:15:09 2019-10-08 04:15:06 evansj  true    false     false
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Full search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=active_directory
| table _time whenChanged Name Enabled LockedOut PasswordExpired
| dedup Name whenChanged sortby -_time
| sort     - whenChanged
| fillnull value="N/A"

| streamstats count by Name
| where count &amp;lt; 3
| fields - count
| transaction maxevents=2 mvlist=true Name

| eval "Updated Fields" = ""
| foreach *
    [ eval "Updated Fields" = if (mvcount('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;') = 2,
                                      if (mvindex('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', 0) = mvindex('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', 1),
                                              'Updated Fields',
                                              'Updated Fields' . "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, "),
                                      'Updated Fields') ]

| eval "Most Recent AD Change Time" = mvindex('whenChanged',1)
| eval "Previous AD Change Time"    = mvindex('whenChanged',0)

| foreach * 
    [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = mvindex('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', -1) ]

| search "Updated Fields" != ""

| table "Previous AD Change Time" "Most Recent AD Change Time" "Updated Fields" Name Enabled LockedOut PasswordExpired
| fillnull value="N/A"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Dissecting the search&lt;/STRONG&gt;&lt;BR /&gt;
Get all unique combinations of Name and whenChanged&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=active_directory
| table _time whenChanged Name Enabled LockedOut PasswordExpired
| dedup Name whenChanged sortby -_time
| sort     - whenChanged
| fillnull value="N/A"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Get the two most recent events by Name, and concatenate them using &lt;CODE&gt;transaction&lt;/CODE&gt; so that there is now one event per name with a multivalue list of all fields. &lt;CODE&gt;mvindex(1)&lt;/CODE&gt; is the more recent value for all fields and &lt;CODE&gt;mvindex(0)&lt;/CODE&gt; is the previous value before that.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| streamstats count by Name
| where count &amp;lt; 3
| fields - count
| transaction maxevents=2 mvlist=true Name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This part is the magic. Create a new field called "Updated Fields". Iterate over all the fields in your table. If the two values in the multivalue are identical, keep "Updated Fields" the same. If they differ, append the name of that field to "Updated Fields". Because I know that &lt;CODE&gt;whenChanged&lt;/CODE&gt; must have changed (or probably &lt;CODE&gt;_time&lt;/CODE&gt; in your query), I can set two new fields knowing which is the more recent and which is the previous value.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval "Updated Fields" = ""
| foreach *
    [ eval "Updated Fields" = if (mvcount('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;') = 2,
                                      if (mvindex('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', 0) = mvindex('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', 1),
                                              'Updated Fields',
                                              'Updated Fields' . "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, "),
                                      'Updated Fields') ]

| eval "Most Recent AD Change Time" = mvindex('whenChanged',1)
| eval "Previous AD Change Time"    = mvindex('whenChanged',0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I don't care what the older values are anymore. You don't need this part if you want to show both values. This just retrieves the most recent value for each field (only for the multivalue fields).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| foreach * 
    [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = mvindex('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', -1) ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If nothing has changed, I'm not interested so discard the event.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| search "Updated Fields" != ""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Sample Output:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Previous AD Change Time  Most Recent AD Change Time  Updated Fields                         Name    Enabled LockedOut PasswordExpired
2019-10-09 03:15:06      2019-10-10 02:15:08         Last AD Change Time, Enabled, LockedOut,  evansj  false   true      false
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
Jacob&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 19:53:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495061#M138033</guid>
      <dc:creator>jacobpevans</dc:creator>
      <dc:date>2019-10-10T19:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields value with old fields value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495062#M138034</link>
      <description>&lt;P&gt;I tried using this search:&lt;BR /&gt;
index=xxx sourcetype= xxxx &lt;BR /&gt;
| fields * &lt;BR /&gt;
| table &lt;EM&gt;time LATITUDE LONGITUDE CELL NAME ADDRESS BAND PCI SITE_ELEV ECELL_ID PSITECODE &lt;BR /&gt;
|streamstats window=1 current=f values(*) as prev&lt;/EM&gt;* by _time&lt;/P&gt;

&lt;P&gt;I get around 10,000 results as this is a big file and it gets updated every week, I just want to see the changes happened over last week or over last month.&lt;/P&gt;

&lt;P&gt;Also the result in statistics needs little tweaking, look below:&lt;BR /&gt;
        _time                               LAT                 LONG              BAND    PCI   ID    ECELL   NAME       Prev_LAT        Prev_LONG    BAND   PCI   ID    ECELL  NAME&lt;BR /&gt;
1   2019-10-10 06:06:02 49.265242   -96.512477   700    8   305 103       ZS&lt;BR /&gt;&lt;BR /&gt;
2   2019-10-10 06:06:02 49.265242   -96.512477   700    7   305 102       ZS        49.265242   -96.512477  700         8   305  103         ZS&lt;/P&gt;

&lt;P&gt;As you can see row one and its previous result show up on row two and it continues like this:&lt;/P&gt;

&lt;P&gt;1&lt;BR /&gt;
2     1&lt;BR /&gt;
3     2&lt;BR /&gt;
4     3&lt;/P&gt;

&lt;P&gt;Also how would I know how old is this previous data. Please help to resolve this.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:26:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495062#M138034</guid>
      <dc:creator>kulwindersandhu</dc:creator>
      <dc:date>2020-09-30T02:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields value with old fields value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495063#M138035</link>
      <description>&lt;P&gt;Hey Jacob, I really appreciate your response. Kindly give me few hours to understand this answer. As I am fairly new to splunk. I'll update once I could come out with some result.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 20:34:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495063#M138035</guid>
      <dc:creator>kulwindersandhu</dc:creator>
      <dc:date>2019-10-10T20:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields value with old fields value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495064#M138036</link>
      <description>&lt;P&gt;I tried the search, it adds a column diditchange to the table, which shows same or not same.  I need to know how old is the data it is comparing with ?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 20:37:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495064#M138036</guid>
      <dc:creator>kulwindersandhu</dc:creator>
      <dc:date>2019-10-10T20:37:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields value with old fields value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495065#M138037</link>
      <description>&lt;P&gt;you know what....streamstats by _time might be a terrible solution for this because you need to compare two different times...sorry...&lt;/P&gt;

&lt;P&gt;this is what you should try:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foo|stats count as _count by _time LATITUDE LONGITUDE CELL NAME ADDRESS BAND PCI SITE_ELEV ECELL_ID PSITECODE|timewrap 1w
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Oct 2019 01:15:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495065#M138037</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2019-10-11T01:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields value with old fields value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495066#M138038</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=YouShouldAlwaysSpecifyAnIndex sourcetype=AndSourcetypeToo (earliest=-1w@d latest=-1w+1d@d OR earliest=@d latest=now)
| rename sourcetype AS Location date_hour AS Band host AS CellID component AS CellName 
| bin _time span=1d 
| fields Location Band CellID CellName 
| stats first(*) AS * BY _time
| stats dc(_time) AS count BY Location Band CellID CellName
| where count==1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Oct 2019 00:28:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495066#M138038</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-10-14T00:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields value with old fields value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495067#M138039</link>
      <description>&lt;P&gt;Hey Jacob, I am trying your suggestion. I want to work extensively on this, would you be available anytime soon to help.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2019 19:29:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495067#M138039</guid>
      <dc:creator>kulwindersandhu</dc:creator>
      <dc:date>2019-10-21T19:29:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields value with old fields value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495068#M138040</link>
      <description>&lt;P&gt;index=XXXsourcetype= XXX&lt;BR /&gt;
| fields whenChanged *&lt;BR /&gt;
| table _time whenChanged LATITUDE LONGITUDE CITY SITE_ID ENODEB_ID CELL_ID BAND CELL_NAME GROUND_ELEVATION_AMSL&lt;BR /&gt;
| dedup CELL_NAME sortby _time&lt;BR /&gt;
| sort CELL_NAME - whenChanged&lt;BR /&gt;
| fillnull value="N/A"&lt;BR /&gt;
| streamstats count by CELL_NAME&lt;BR /&gt;
| where count &amp;lt; 3&lt;BR /&gt;
| fields - count&lt;BR /&gt;
| transaction maxevents=2 mvlist=true CELL_NAME&lt;BR /&gt;
| eval "Updated Fields" = "NEW_CHANGES"&lt;BR /&gt;
 | foreach *&lt;BR /&gt;
     [ eval "Updated Fields" = if (mvcount('CELL_NAME') = 2,&lt;BR /&gt;
                                       if (mvindex('CELL_NAME', 0) = mvindex('CELL_NAME', 1),&lt;BR /&gt;
                                               'Updated Fields',&lt;BR /&gt;
                                               'Updated Fields' . "CELL_NAME, "),&lt;BR /&gt;
                                       'Updated Fields') ]&lt;BR /&gt;
 | eval "Most Recent AD Change Time" = mvindex('whenChanged',1)&lt;BR /&gt;
 | eval "Previous AD Change Time"    = mvindex('whenChanged',0)&lt;/P&gt;

&lt;P&gt;This is what I used, it just shows all parameters with a new field whenChanged. I want to see new additions and changes and I am not able to see them. Please help.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:35:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-value-with-old-fields-value/m-p/495068#M138040</guid>
      <dc:creator>kulwindersandhu</dc:creator>
      <dc:date>2020-09-30T02:35:08Z</dc:date>
    </item>
  </channel>
</rss>

