<?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 Adding a Total column (without using addtotals) in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700657#M237722</link>
    <description>&lt;P&gt;Sometimes I set myself SPL conundrum challenges just to see how to solve them.&amp;nbsp; I realised I couldn't do something I thought would be quite straightforward.&amp;nbsp; For the dummy data below I want a single row resultset which tells me how many events of each UpgradeStatus and how&amp;nbsp; many events in total i.e.&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%"&gt;Total&lt;/TD&gt;&lt;TD width="25%"&gt;Completed&lt;/TD&gt;&lt;TD width="25%"&gt;Pending&lt;/TD&gt;&lt;TD width="25%"&gt;Processing&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;11&lt;/TD&gt;&lt;TD width="25%"&gt;6&lt;/TD&gt;&lt;TD width="25%"&gt;3&lt;/TD&gt;&lt;TD width="25%"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp; I don't know in advance what the different values of UpgradeStatus might be and I don't want to use addtotals (this is the challenge part).&lt;/P&gt;&lt;P&gt;I came up with the solution below which kinda "misuses" xyseries (which I'm strangely proud of) .&amp;nbsp; I feel like I'm missing a more straightforward solution, other than &lt;EM&gt;addtotals&lt;/EM&gt; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; Anyone up for the challenge?&lt;/P&gt;&lt;P&gt;Dummy data and solution (misusing &lt;EM&gt;xyseries&lt;/EM&gt;) follows...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults format=csv data="ServerName,UpgradeStatus
Server1,Completed
Server2,Completed
Server3,Completed
Server4,Completed
Server5,Completed
Server6,Completed
Server7,Pending
Server8,Pending
Server9,Pending
Server10,Processing
Server11,Processing" 
| stats count by UpgradeStatus 
| eventstats sum(count) as Total 
| xyseries Total UpgradeStatus count&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Oct 2024 13:06:52 GMT</pubDate>
    <dc:creator>tread_splunk</dc:creator>
    <dc:date>2024-10-01T13:06:52Z</dc:date>
    <item>
      <title>Adding a Total column (without using addtotals)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700657#M237722</link>
      <description>&lt;P&gt;Sometimes I set myself SPL conundrum challenges just to see how to solve them.&amp;nbsp; I realised I couldn't do something I thought would be quite straightforward.&amp;nbsp; For the dummy data below I want a single row resultset which tells me how many events of each UpgradeStatus and how&amp;nbsp; many events in total i.e.&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%"&gt;Total&lt;/TD&gt;&lt;TD width="25%"&gt;Completed&lt;/TD&gt;&lt;TD width="25%"&gt;Pending&lt;/TD&gt;&lt;TD width="25%"&gt;Processing&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;11&lt;/TD&gt;&lt;TD width="25%"&gt;6&lt;/TD&gt;&lt;TD width="25%"&gt;3&lt;/TD&gt;&lt;TD width="25%"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp; I don't know in advance what the different values of UpgradeStatus might be and I don't want to use addtotals (this is the challenge part).&lt;/P&gt;&lt;P&gt;I came up with the solution below which kinda "misuses" xyseries (which I'm strangely proud of) .&amp;nbsp; I feel like I'm missing a more straightforward solution, other than &lt;EM&gt;addtotals&lt;/EM&gt; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; Anyone up for the challenge?&lt;/P&gt;&lt;P&gt;Dummy data and solution (misusing &lt;EM&gt;xyseries&lt;/EM&gt;) follows...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults format=csv data="ServerName,UpgradeStatus
Server1,Completed
Server2,Completed
Server3,Completed
Server4,Completed
Server5,Completed
Server6,Completed
Server7,Pending
Server8,Pending
Server9,Pending
Server10,Processing
Server11,Processing" 
| stats count by UpgradeStatus 
| eventstats sum(count) as Total 
| xyseries Total UpgradeStatus count&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2024 13:06:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700657#M237722</guid>
      <dc:creator>tread_splunk</dc:creator>
      <dc:date>2024-10-01T13:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Total column (without using addtotals)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700658#M237723</link>
      <description>&lt;LI-CODE lang="markup"&gt;| makeresults format=csv data="ServerName,UpgradeStatus
Server1,Completed
Server2,Completed
Server3,Completed
Server4,Completed
Server5,Completed
Server6,Completed
Server7,Pending
Server8,Pending
Server9,Pending
Server10,Processing
Server11,Processing"
| eventstats count as Total
| chart count by Total UpgradeStatus&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 01 Oct 2024 13:20:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700658#M237723</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-10-01T13:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Total column (without using addtotals)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700664#M237726</link>
      <description>&lt;P&gt;There isn't a search that can't be made uglier with foreach XD&lt;/P&gt;&lt;PRE&gt;| makeresults format=csv data="ServerName,UpgradeStatus&lt;BR /&gt;Server1,Completed&lt;BR /&gt;Server2,Completed&lt;BR /&gt;Server3,Completed&lt;BR /&gt;Server4,Completed&lt;BR /&gt;Server5,Completed&lt;BR /&gt;Server6,Completed&lt;BR /&gt;Server7,Pending&lt;BR /&gt;Server8,Pending&lt;BR /&gt;Server9,Pending&lt;BR /&gt;Server10,Processing&lt;BR /&gt;Server11,Processing"&lt;BR /&gt;| stats count by UpgradeStatus&lt;BR /&gt;| transpose 0 header_field=UpgradeStatus &lt;BR /&gt;| fields - column&lt;BR /&gt;| eval Total=0&lt;BR /&gt;| foreach * &lt;BR /&gt;    [ eval Total=Total+&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; ]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;As an alternative you can also use appendpipe&lt;/P&gt;&lt;PRE&gt;| makeresults format=csv data="ServerName,UpgradeStatus&lt;BR /&gt;Server1,Completed&lt;BR /&gt;Server2,Completed&lt;BR /&gt;Server3,Completed&lt;BR /&gt;Server4,Completed&lt;BR /&gt;Server5,Completed&lt;BR /&gt;Server6,Completed&lt;BR /&gt;Server7,Pending&lt;BR /&gt;Server8,Pending&lt;BR /&gt;Server9,Pending&lt;BR /&gt;Server10,Processing&lt;BR /&gt;Server11,Processing"&lt;BR /&gt;| stats count by UpgradeStatus&lt;BR /&gt;| appendpipe &lt;BR /&gt;    [ stats sum(count) as count &lt;BR /&gt;    | eval UpgradeStatus="Total" ]&lt;BR /&gt;| transpose 0 header_field=UpgradeStatus&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Oct 2024 13:50:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700664#M237726</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-10-01T13:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Total column (without using addtotals)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700670#M237728</link>
      <description>&lt;P&gt;Nice work&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231884"&gt;@PickleRick&lt;/a&gt;&amp;nbsp;!&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I missing something?&amp;nbsp; I had previously tried with the delightful &lt;EM&gt;foreach&lt;/EM&gt; command earlier but I can't get it to avoid double-counting the Total field.&amp;nbsp; So I end up with the Total equalling 22 - not the correct result of 11.&amp;nbsp; I get the same thing with your solution as well.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2024 14:04:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700670#M237728</guid>
      <dc:creator>tread_splunk</dc:creator>
      <dc:date>2024-10-01T14:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Total column (without using addtotals)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700672#M237729</link>
      <description>&lt;P&gt;Right you are. As usual, forgot about it.&lt;/P&gt;&lt;P&gt;Here's fixed version.&lt;/P&gt;&lt;PRE&gt;| makeresults format=csv data="ServerName,UpgradeStatus&lt;BR /&gt;Server1,Completed&lt;BR /&gt;Server2,Completed&lt;BR /&gt;Server3,Completed&lt;BR /&gt;Server4,Completed&lt;BR /&gt;Server5,Completed&lt;BR /&gt;Server6,Completed&lt;BR /&gt;Server7,Pending&lt;BR /&gt;Server8,Pending&lt;BR /&gt;Server9,Pending&lt;BR /&gt;Server10,Processing&lt;BR /&gt;Server11,Processing"&lt;BR /&gt;| stats count by UpgradeStatus&lt;BR /&gt;| transpose 0 header_field=UpgradeStatus &lt;BR /&gt;| fields - column&lt;BR /&gt;| eval Total=0&lt;BR /&gt;| foreach *&lt;BR /&gt;    [ eval Total=Total+if("&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"=="Total",0,&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;) ]&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Oct 2024 14:09:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700672#M237729</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-10-01T14:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Total column (without using addtotals)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700673#M237730</link>
      <description>&lt;P&gt;Oh&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;That is sweet.&lt;/P&gt;&lt;P&gt;It helps me if I&amp;nbsp;specify the &lt;EM&gt;over / by&lt;/EM&gt; designation ... but hats off to you.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eventstats count as Total
| chart count over Total by UpgradeStatus&lt;/LI-CODE&gt;&lt;P&gt;Not looking forward to explaining to anyone how it works ... but work it does.&amp;nbsp; (I'll add it to my collection of misusing a command to get a result.&amp;nbsp; &amp;nbsp;Got any others? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;)&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2024 14:15:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700673#M237730</guid>
      <dc:creator>tread_splunk</dc:creator>
      <dc:date>2024-10-01T14:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Total column (without using addtotals)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700676#M237732</link>
      <description>&lt;P&gt;Aha!&amp;nbsp; That's how you avoid the double-count.&amp;nbsp; I've encountered this before.&amp;nbsp; Will definitely put this on file.&amp;nbsp; Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2024 14:18:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700676#M237732</guid>
      <dc:creator>tread_splunk</dc:creator>
      <dc:date>2024-10-01T14:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Total column (without using addtotals)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700677#M237733</link>
      <description>&lt;P&gt;Alternatively you could just to a very ugly hack and name your field so it will be iterated over at the end and knowing it will be added to itself just divide it in half &lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2024 14:18:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700677#M237733</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-10-01T14:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Total column (without using addtotals)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700680#M237734</link>
      <description>&lt;P&gt;I tend to just use the by clause as the first mentioned field is used for the over field, but that's just a matter of style / preference. Since you can only specify two fields on a chart command, over and by is probably clearer.&lt;/P&gt;&lt;P&gt;In this example, the eventstats is a way of providing a single value for the "over" field so that you get a single row of statistics.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2024 14:30:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Total-column-without-using-addtotals/m-p/700680#M237734</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-10-01T14:30:49Z</dc:date>
    </item>
  </channel>
</rss>

