<?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 do I substract the results of two different searches including sseabalytics ? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-substract-the-results-of-two-different-searches/m-p/696753#M236797</link>
    <description>&lt;P&gt;Hi thanks for pointing that out.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;The&amp;nbsp; &amp;nbsp;&lt;EM&gt;"by bookmark_status_display"&amp;nbsp; &amp;nbsp;&lt;/EM&gt;was indeed unneeded as I'm specifying&amp;nbsp; which status it is in the query&amp;nbsp; hence the&amp;nbsp; actual query should be:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| sseanalytics 'bookmark'
| where bookmark_status="bookmarked"
| stats count(bookmark_status_display) AS "Bookmark Status"
&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;-&amp;nbsp; Once taking that into considereation i was able to use the following for the result :&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| rest /services/saved/searches
| search alert_type!="always" AND action.email.to="production@email.com" AND title!="*test*"
| stats count(action.email.to) AS "Count"
| appendcols
[sseanalytics 'bookmark'
| where bookmark_status="successfullyImplemented"
| stats count(bookmark_status_display) AS "Bookmark Status"]
| eventstats values(Count) as Count
| eval diff = 'Bookmark Status' - Count
| table diff&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;Thank you 100!&lt;/P&gt;</description>
    <pubDate>Mon, 19 Aug 2024 18:02:22 GMT</pubDate>
    <dc:creator>AcePilot</dc:creator>
    <dc:date>2024-08-19T18:02:22Z</dc:date>
    <item>
      <title>How do I substract the results of two different searches including sseabalytics ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-substract-the-results-of-two-different-searches/m-p/696546#M236726</link>
      <description>&lt;P&gt;Im trying to substract&amp;nbsp; the total number i have of alerts that send and email&amp;nbsp; from the total amount of alerts that are bookmarked in SSE.&amp;nbsp; The only examples I found on the community used either the same index, or sub-searches (neither worked in my scenario)&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;My query for&amp;nbsp; the alerts is :&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| rest /services/saved/searches | search alert_type!="always" AND action.email.to="production@email.com" AND title!="*test*" 
| stats count(action.email.to) AS "Count"
&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;My query for bookmarks is:&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| sseanalytics 'bookmark'
| where bookmark_status="successfullyImplemented"
| stats count(bookmark_status_display) AS "Bookmark Status" by bookmark_status_display&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 16 Aug 2024 21:12:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-substract-the-results-of-two-different-searches/m-p/696546#M236726</guid>
      <dc:creator>AcePilot</dc:creator>
      <dc:date>2024-08-16T21:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I substract the results of two different searches including sseabalytics ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-substract-the-results-of-two-different-searches/m-p/696556#M236731</link>
      <description>&lt;P&gt;You realize that the first search results in one single row, and the second gives a series of rows, right? &amp;nbsp;Without illustrating or describing what your desired output look like, you are asking volunteers to read your mind. &amp;nbsp;This is generally a bad idea on a forum like this.&lt;/P&gt;&lt;P&gt;If your requirement is to subtract singular Count in the first search from "Bookmark Status" in every row in the second search, you can do something as simple as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rest /services/saved/searches
| search alert_type!="always" AND action.email.to="production@email.com" AND title!="*test*" 
| stats count(action.email.to) AS "Count"
| appendcols
    [sseanalytics 'bookmark'
    | where bookmark_status="successfullyImplemented"
    | stats count(bookmark_status_display) AS "Bookmark Status" by bookmark_status_display]
| eventstats values(Count) as Count
| eval diff = 'Bookmark Status' - Count&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here I am using appendcols instead of the usual approach using append because one of the searches only gives out one single row. &amp;nbsp;This is not the most semantic approach but sometimes I like code economy. &amp;nbsp;In fact, this method applies to any two searches as long as one of them yields a single row.&lt;/P&gt;&lt;P&gt;Here is an emulation as proof of concept:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats count AS Count where index=_internal
``` the above emulates
| rest /services/saved/searches | search alert_type!="always" AND action.email.to="production@email.com" AND title!="*test*" 
| stats count(action.email.to) AS "Count"
```
| appendcols
    [tstats count AS "Bookmark Status"  where index=_introspection by sourcetype
    | rename sourcetype AS bookmark_status_display
    ``` this subsearch emulates
    | sseanalytics 'bookmark'
    | where bookmark_status="successfullyImplemented"
    | stats count(bookmark_status_display) AS "Bookmark Status" by bookmark_status_display
    ```
    ]
| eventstats values(Count) as Count
| eval diff = 'Bookmark Status' - Count&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You will get something like&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Count&lt;/TD&gt;&lt;TD&gt;Bookmark Status&lt;/TD&gt;&lt;TD&gt;bookmark_status_display&lt;/TD&gt;&lt;TD&gt;diff&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;151857&lt;/TD&gt;&lt;TD&gt;201&lt;/TD&gt;&lt;TD&gt;http_event_collector_metrics&lt;/TD&gt;&lt;TD&gt;-151656&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;151857&lt;/TD&gt;&lt;TD&gt;2365&lt;/TD&gt;&lt;TD&gt;kvstore&lt;/TD&gt;&lt;TD&gt;-149492&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;151857&lt;/TD&gt;&lt;TD&gt;57&lt;/TD&gt;&lt;TD&gt;search_telemetry&lt;/TD&gt;&lt;TD&gt;-151800&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;151857&lt;/TD&gt;&lt;TD&gt;462&lt;/TD&gt;&lt;TD&gt;splunk_disk_objects&lt;/TD&gt;&lt;TD&gt;-151395&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;151857&lt;/TD&gt;&lt;TD&gt;303&lt;/TD&gt;&lt;TD&gt;splunk_telemetry&lt;/TD&gt;&lt;TD&gt;-151554&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sat, 17 Aug 2024 06:10:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-substract-the-results-of-two-different-searches/m-p/696556#M236731</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-08-17T06:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I substract the results of two different searches including sseabalytics ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-substract-the-results-of-two-different-searches/m-p/696559#M236733</link>
      <description>&lt;P&gt;Apart from the technicalities which &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt; already tackled, there is also a logical flaw in your approach. Even if you aggregate your second search output into a single count you have two relatively unrelated values. Substracting cardinalities makes sense only if one set is a subset of another one. In your case those sets may overlap but one doesn't have to be included in the other.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2024 07:03:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-substract-the-results-of-two-different-searches/m-p/696559#M236733</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-08-17T07:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I substract the results of two different searches including sseabalytics ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-substract-the-results-of-two-different-searches/m-p/696753#M236797</link>
      <description>&lt;P&gt;Hi thanks for pointing that out.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;The&amp;nbsp; &amp;nbsp;&lt;EM&gt;"by bookmark_status_display"&amp;nbsp; &amp;nbsp;&lt;/EM&gt;was indeed unneeded as I'm specifying&amp;nbsp; which status it is in the query&amp;nbsp; hence the&amp;nbsp; actual query should be:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| sseanalytics 'bookmark'
| where bookmark_status="bookmarked"
| stats count(bookmark_status_display) AS "Bookmark Status"
&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;-&amp;nbsp; Once taking that into considereation i was able to use the following for the result :&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| rest /services/saved/searches
| search alert_type!="always" AND action.email.to="production@email.com" AND title!="*test*"
| stats count(action.email.to) AS "Count"
| appendcols
[sseanalytics 'bookmark'
| where bookmark_status="successfullyImplemented"
| stats count(bookmark_status_display) AS "Bookmark Status"]
| eventstats values(Count) as Count
| eval diff = 'Bookmark Status' - Count
| table diff&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;Thank you 100!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 18:02:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-substract-the-results-of-two-different-searches/m-p/696753#M236797</guid>
      <dc:creator>AcePilot</dc:creator>
      <dc:date>2024-08-19T18:02:22Z</dc:date>
    </item>
  </channel>
</rss>

