<?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: compare data in two columns in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/compare-data-in-two-columns/m-p/712316#M240323</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;is there something wrong in the logic or alternate way to do it&amp;nbsp;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Yes, the logic is wrong with the given dataset. &amp;nbsp;But before I explain, please remember to post sample data in text for others to check even when screenshot helps illustrate the problem you are trying to diagnose. &amp;nbsp;So, here is your sample data:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;GroupA&lt;/TD&gt;&lt;TD&gt;GroupB&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353649273&lt;/TD&gt;&lt;TD&gt;353648649&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353649184&lt;/TD&gt;&lt;TD&gt;353648566&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353649091&lt;/TD&gt;&lt;TD&gt;353616829&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353649033&lt;/TD&gt;&lt;TD&gt;353638941&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353648797&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353648680&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353648745&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353648730&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353638941&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;From this dataset, it is easy to see that there is no match in any event. (One event is represented by one row.) &amp;nbsp;In addition to this, if you are going to compare GroupA and GroupB in their original names, there is no need to use foreach. &amp;nbsp;The logic expressed in your SPL can easily be implemented with&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;eval match=if(GroupA=GroupB,GroupA ,null())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Two SPL pointers: 1) use eval function null() is more expressive AND does not spend CPU cycles to look for a nonexistent field name such as NULL; more importantly, 2) foreach operates on a each event (row) individually. &amp;nbsp;If there is no match within the same event, match will always receive null value.&lt;/P&gt;&lt;P&gt;On the second point,&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/170906"&gt;@livehybrid&lt;/a&gt;&amp;nbsp;makes a speculation of your real intent, which seems to be to seek not a match in individual events between string/numerical fields GroupA and GroupB, but to seek matches in the sets of all values of GroupA and all values of GroupB. &amp;nbsp;Is this the correct interpretation? &amp;nbsp;If so, your first logical mistake is to misinterpret the problem to be comparison within individual events.&lt;/P&gt;&lt;P&gt;A second mistake you make is in problem statement.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;i have data from two columns and using a third column to display the matches&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Given that there is no same-event match, your intention of "using a third column to display the matches" becomes impossible for volunteers here to interpret. &amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/170906"&gt;@livehybrid&lt;/a&gt;&amp;nbsp;made an effort to interpret your intention as "if any value in the set of all values of GroupA matches any values in the set of all values of GroupB, display the matching values in GroupA together with &lt;STRONG&gt;ALL&lt;/STRONG&gt; values of GroupB. (As opposed to any specific values of GroupB.)" &amp;nbsp;The output from that code is&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;GroupA&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;GroupB&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;match&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353638941&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;353616829&lt;/DIV&gt;&lt;DIV class=""&gt;353638941&lt;/DIV&gt;&lt;DIV class=""&gt;353648566&lt;/DIV&gt;&lt;DIV class=""&gt;353648649&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Is this what you expect? &amp;nbsp;What if there are two distinct values in GroupA matching two values GroupB, should the column GroupA display the two matching values and the column GroupB still displaying the same five values?&lt;/P&gt;&lt;P&gt;It all comes down to the four golden rules in asking questions in this forum that I call Four Commandments:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Illustrate data input (in raw text, anonymize as needed), whether they are raw events or output from a search (SPL that volunteers here do not have to look at).&lt;/LI&gt;&lt;LI&gt;Illustrate the desired output from illustrated data.&lt;/LI&gt;&lt;LI&gt;Explain the logic between illustrated data and desired output&amp;nbsp;&lt;EM&gt;without&lt;/EM&gt;&amp;nbsp;SPL.&lt;/LI&gt;&lt;LI&gt;If you also illustrate attempted SPL, illustrate actual output and compare with desired output, explain why they look different&amp;nbsp;&lt;U&gt;to you&lt;/U&gt;&amp;nbsp;if that is not painfully obvious.&lt;/LI&gt;&lt;/UL&gt;</description>
    <pubDate>Sun, 23 Feb 2025 19:37:45 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2025-02-23T19:37:45Z</dc:date>
    <item>
      <title>compare data in two columns</title>
      <link>https://community.splunk.com/t5/Splunk-Search/compare-data-in-two-columns/m-p/712009#M240278</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have data from two columns and using a third column to display the matches&lt;/P&gt;&lt;P&gt;| makeresults&lt;BR /&gt;| eval GroupA = 353649273, GroupB=353648649&lt;BR /&gt;| append&lt;BR /&gt;[ | makeresults | eval GroupA = 353649184, GroupB=353648566]&lt;BR /&gt;| append&lt;BR /&gt;[ | makeresults | eval GroupA = 353649091, GroupB=353616829]&lt;BR /&gt;| append&lt;BR /&gt;[ | makeresults | eval GroupA = 353649033, GroupB=353638941]&lt;BR /&gt;| append&lt;BR /&gt;[ | makeresults | eval GroupA = 353648797]&lt;BR /&gt;| append&lt;BR /&gt;[ | makeresults | eval GroupA = 353648680]&lt;BR /&gt;| append&lt;BR /&gt;[ | makeresults | eval GroupA = 353648745]&lt;BR /&gt;| append&lt;BR /&gt;[ | makeresults | eval GroupA = 353648730]&lt;BR /&gt;| append&lt;BR /&gt;[ | makeresults | eval GroupA = 353638941]&lt;BR /&gt;| fields - _time&lt;BR /&gt;| foreach GroupA [eval match=if(GroupA=GroupB,GroupA ,NULL)] | stats values(GroupA) values(GroupB) values(match)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="secure_0-1739979859672.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/34624i9A2D6F98342DCAED/image-size/medium?v=v2&amp;amp;px=400" role="button" title="secure_0-1739979859672.png" alt="secure_0-1739979859672.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;however nothing is getting displayed in values(match). is there something wrong in the logic or alternate way to do it&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 15:44:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/compare-data-in-two-columns/m-p/712009#M240278</guid>
      <dc:creator>secure</dc:creator>
      <dc:date>2025-02-19T15:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: compare data in two columns</title>
      <link>https://community.splunk.com/t5/Splunk-Search/compare-data-in-two-columns/m-p/712018#M240282</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/274955"&gt;@secure&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How about this?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval GroupA = 353649273, GroupB=353648649
| append
[ | makeresults | eval GroupA = 353649184, GroupB=353648566]
| append
[ | makeresults | eval GroupA = 353649091, GroupB=353616829]
| append
[ | makeresults | eval GroupA = 353649033, GroupB=353638941]
| append
[ | makeresults | eval GroupA = 353648797]
| append
[ | makeresults | eval GroupA = 353648680]
| append
[ | makeresults | eval GroupA = 353648745]
| append
[ | makeresults | eval GroupA = 353648730]
| append
[ | makeresults | eval GroupA = 353638941]
| fields - _time
| eventstats values(GroupB) AS GroupB
| eval match=IF(match(GroupB,GroupA),1,0)
| where match=1&lt;/LI-CODE&gt;&lt;P&gt;Please let me know how you get on and consider accepting this answer or adding karma this answer if it has helped.&lt;BR /&gt;Regards&lt;/P&gt;&lt;P&gt;Will&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 16:21:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/compare-data-in-two-columns/m-p/712018#M240282</guid>
      <dc:creator>livehybrid</dc:creator>
      <dc:date>2025-02-19T16:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: compare data in two columns</title>
      <link>https://community.splunk.com/t5/Splunk-Search/compare-data-in-two-columns/m-p/712305#M240322</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/274955"&gt;@secure&lt;/a&gt;- Probably custom command from this App might help.&lt;/P&gt;&lt;P&gt;&lt;A href="https://splunkbase.splunk.com/app/4297" target="_blank"&gt;https://splunkbase.splunk.com/app/4297&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VatsalJagani_0-1740319836315.png" style="width: 782px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/34670i1E519C585B4FCC82/image-dimensions/782x247?v=v2" width="782" height="247" role="button" title="VatsalJagani_0-1740319836315.png" alt="VatsalJagani_0-1740319836315.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly upvote if it helps!!!&lt;/P&gt;</description>
      <pubDate>Sun, 23 Feb 2025 14:10:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/compare-data-in-two-columns/m-p/712305#M240322</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2025-02-23T14:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: compare data in two columns</title>
      <link>https://community.splunk.com/t5/Splunk-Search/compare-data-in-two-columns/m-p/712316#M240323</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;is there something wrong in the logic or alternate way to do it&amp;nbsp;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Yes, the logic is wrong with the given dataset. &amp;nbsp;But before I explain, please remember to post sample data in text for others to check even when screenshot helps illustrate the problem you are trying to diagnose. &amp;nbsp;So, here is your sample data:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;GroupA&lt;/TD&gt;&lt;TD&gt;GroupB&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353649273&lt;/TD&gt;&lt;TD&gt;353648649&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353649184&lt;/TD&gt;&lt;TD&gt;353648566&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353649091&lt;/TD&gt;&lt;TD&gt;353616829&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353649033&lt;/TD&gt;&lt;TD&gt;353638941&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353648797&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353648680&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353648745&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353648730&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353638941&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;From this dataset, it is easy to see that there is no match in any event. (One event is represented by one row.) &amp;nbsp;In addition to this, if you are going to compare GroupA and GroupB in their original names, there is no need to use foreach. &amp;nbsp;The logic expressed in your SPL can easily be implemented with&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;eval match=if(GroupA=GroupB,GroupA ,null())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Two SPL pointers: 1) use eval function null() is more expressive AND does not spend CPU cycles to look for a nonexistent field name such as NULL; more importantly, 2) foreach operates on a each event (row) individually. &amp;nbsp;If there is no match within the same event, match will always receive null value.&lt;/P&gt;&lt;P&gt;On the second point,&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/170906"&gt;@livehybrid&lt;/a&gt;&amp;nbsp;makes a speculation of your real intent, which seems to be to seek not a match in individual events between string/numerical fields GroupA and GroupB, but to seek matches in the sets of all values of GroupA and all values of GroupB. &amp;nbsp;Is this the correct interpretation? &amp;nbsp;If so, your first logical mistake is to misinterpret the problem to be comparison within individual events.&lt;/P&gt;&lt;P&gt;A second mistake you make is in problem statement.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;i have data from two columns and using a third column to display the matches&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Given that there is no same-event match, your intention of "using a third column to display the matches" becomes impossible for volunteers here to interpret. &amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/170906"&gt;@livehybrid&lt;/a&gt;&amp;nbsp;made an effort to interpret your intention as "if any value in the set of all values of GroupA matches any values in the set of all values of GroupB, display the matching values in GroupA together with &lt;STRONG&gt;ALL&lt;/STRONG&gt; values of GroupB. (As opposed to any specific values of GroupB.)" &amp;nbsp;The output from that code is&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;GroupA&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;GroupB&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;match&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;353638941&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;353616829&lt;/DIV&gt;&lt;DIV class=""&gt;353638941&lt;/DIV&gt;&lt;DIV class=""&gt;353648566&lt;/DIV&gt;&lt;DIV class=""&gt;353648649&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Is this what you expect? &amp;nbsp;What if there are two distinct values in GroupA matching two values GroupB, should the column GroupA display the two matching values and the column GroupB still displaying the same five values?&lt;/P&gt;&lt;P&gt;It all comes down to the four golden rules in asking questions in this forum that I call Four Commandments:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Illustrate data input (in raw text, anonymize as needed), whether they are raw events or output from a search (SPL that volunteers here do not have to look at).&lt;/LI&gt;&lt;LI&gt;Illustrate the desired output from illustrated data.&lt;/LI&gt;&lt;LI&gt;Explain the logic between illustrated data and desired output&amp;nbsp;&lt;EM&gt;without&lt;/EM&gt;&amp;nbsp;SPL.&lt;/LI&gt;&lt;LI&gt;If you also illustrate attempted SPL, illustrate actual output and compare with desired output, explain why they look different&amp;nbsp;&lt;U&gt;to you&lt;/U&gt;&amp;nbsp;if that is not painfully obvious.&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Sun, 23 Feb 2025 19:37:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/compare-data-in-two-columns/m-p/712316#M240323</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2025-02-23T19:37:45Z</dc:date>
    </item>
  </channel>
</rss>

