<?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: Removing duplicates from 2 multivalue field (leaving distinct values only) in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Removing-duplicates-from-2-multivalue-field-leaving-distinct/m-p/671736#M230160</link>
    <description>&lt;LI-CODE lang="markup"&gt;| eval groups=mvappend(old, old, new)
| stats count by user groups&lt;/LI-CODE&gt;&lt;P&gt;Where count=3, the group exists in both old and new&lt;/P&gt;&lt;P&gt;Where count=2, the group exists just in old&lt;/P&gt;&lt;P&gt;Where count=1, the group exists just in new&lt;/P&gt;</description>
    <pubDate>Wed, 13 Dec 2023 14:16:37 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2023-12-13T14:16:37Z</dc:date>
    <item>
      <title>Removing duplicates from 2 multivalue field (leaving distinct values only)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-duplicates-from-2-multivalue-field-leaving-distinct/m-p/671688#M230148</link>
      <description>&lt;P&gt;I have 2 multivalue fields (old and new) containing group lists for 1 or more users. The new values is the list of groups that replace the old groups&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;user 1 has an old value of group1, group2, group3&lt;BR /&gt;user 1 has a new value of group1, group2, group3, group4, and group5&lt;BR /&gt;user 2 has an old value of group3, group4, group5&lt;BR /&gt;user 1 has a new value of group4, group5, group6, group7, and group8&lt;/P&gt;&lt;P&gt;I'm trying to return group4 and group5 for user and group7 and group8 for user2&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 10:21:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-duplicates-from-2-multivalue-field-leaving-distinct/m-p/671688#M230148</guid>
      <dc:creator>diskioinferno</dc:creator>
      <dc:date>2023-12-13T10:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates from 2 multivalue field (leaving distinct values only)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-duplicates-from-2-multivalue-field-leaving-distinct/m-p/671736#M230160</link>
      <description>&lt;LI-CODE lang="markup"&gt;| eval groups=mvappend(old, old, new)
| stats count by user groups&lt;/LI-CODE&gt;&lt;P&gt;Where count=3, the group exists in both old and new&lt;/P&gt;&lt;P&gt;Where count=2, the group exists just in old&lt;/P&gt;&lt;P&gt;Where count=1, the group exists just in new&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 14:16:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-duplicates-from-2-multivalue-field-leaving-distinct/m-p/671736#M230160</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-12-13T14:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates from 2 multivalue field (leaving distinct values only)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-duplicates-from-2-multivalue-field-leaving-distinct/m-p/671743#M230161</link>
      <description>&lt;P&gt;I think you should be able to do this by using the mvmap() function.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dtburrows3_0-1702479817788.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/28489i94FCAAFA7897C689/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dtburrows3_0-1702479817788.png" alt="dtburrows3_0-1702479817788.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Here is the eval to return the resulting table above.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;``` Eval to perform set operation against Splunk multivalue fields ```
    | eval
        new_remove_old_set_operation=case(
            isnull(new_groups), null(),
            mvcount(new_groups)==1, if(NOT 'new_groups'=='old_groups', 'new_groups', null()),
            mvcount(new_groups)&amp;gt;1, mvmap(new_groups, if(NOT 'new_groups'=='old_groups', 'new_groups', null()))
            )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Full SPL snippet used to replicate your scenario.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
    | eval
        user="user1",
        old_groups=mvappend(
            "group1",
            "group2",
            "group3"
            ),
        new_groups=mvappend(
            "group1",
            "group2",
            "group3",
            "group4",
            "group5"
            )
    | append
        [
            | makeresults
                | eval
                    user="user2",
                    old_groups=mvappend(
                        "group3",
                        "group4",
                        "group5"
                        ),
                    new_groups=mvappend(
                        "group4",
                        "group5",
                        "group6",
                        "group7",
                        "group8"
                        )
            ]
    | fields - _time
    | fields + user, old_groups, new_groups
    ``` Eval to perform set operation against Splunk multivalue fields ```
    | eval
        new_remove_old_set_operation=case(
            isnull(new_groups), null(),
            mvcount(new_groups)==1, if(NOT 'new_groups'=='old_groups', 'new_groups', null()),
            mvcount(new_groups)&amp;gt;1, mvmap(new_groups, if(NOT 'new_groups'=='old_groups', 'new_groups', null()))
            )&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 15:05:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-duplicates-from-2-multivalue-field-leaving-distinct/m-p/671743#M230161</guid>
      <dc:creator>dtburrows3</dc:creator>
      <dc:date>2023-12-13T15:05:20Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates from 2 multivalue field (leaving distinct values only)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-duplicates-from-2-multivalue-field-leaving-distinct/m-p/672132#M230271</link>
      <description>&lt;P&gt;This worked, &amp;nbsp;thank you! I had looked at mvmap but this was not the how I was trying to use it - thanks for your help&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2023 02:42:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-duplicates-from-2-multivalue-field-leaving-distinct/m-p/672132#M230271</guid>
      <dc:creator>diskioinferno</dc:creator>
      <dc:date>2023-12-18T02:42:07Z</dc:date>
    </item>
  </channel>
</rss>

