Splunk Search

Add sum events in separate column

khanlarloo
Explorer

it is my search
host="splunk.local"|bucket _time span=1mon | stats count by event
alt text

my question is :
To sum the total number of events per month in a seprate field
but when i use this query
host="splunk.local"|bucket _time span=1mon | stats count by event | stats sum(count) as total
alt text
the event field disappear i want to have event and count and the total field in my search.
i try this
host="splunk.local"|bucket _time span=1mon | stats count by event| eventstats sum(count) as total|table event total
but it shows the result in all the column, not just on row
how can i solve my problem?

tanx

0 Karma
1 Solution

niketn
Legend

@khanlarloo, you have following options

Option 1: Use addcoltotals command to calculate column total

<YourBaseSearchWithIndexAndSourcetype> host="splunk.local"
| addcoltotals labelfield=event label=Total

PS: Since you are not showing _time in your stats I don't think you need |bucket _time span=1mon, and in case you do, timechart would be a better command
Option 2: Use addtotals command to calculate column total using row=f col=t

<YourBaseSearchWithIndexAndSourcetype> host="splunk.local"
| addcoltotals row=f col=t labelfield=event label=Total

Option 3: If you are on Splunk 6.5 or greater you can use Simple XML Chart configuration option totalsRow set to true

    <option name="totalsRow">true</option>

Following is a run anywhere dashboard based on Splunk _internal index which elaborates all three options:

<dashboard>
  <label>Total Of Field values</label>
  <row>
    <panel>
      <title>Option 1 : SimpleXML option totalsRow = true</title>
      <table>
        <search>
          <query>index=_internal sourcetype=splunkd
| stats count by component
| sort - count 
| head 10
</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
        </search>
        <option name="count">20</option>
        <option name="dataOverlayMode">none</option>
        <option name="drilldown">none</option>
        <option name="percentagesRow">false</option>
        <option name="rowNumbers">false</option>
        <option name="totalsRow">true</option>
        <option name="wrap">true</option>
      </table>
    </panel>
  </row>
  <row>
    <panel>
      <title>Option 2 : addcoltotals command</title>
      <table>
        <search>
          <query>index=_internal sourcetype=splunkd
| stats count by component
| sort - count 
| head 10
| addcoltotals labelfield=component label=Total</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
        </search>
        <option name="count">20</option>
        <option name="dataOverlayMode">none</option>
        <option name="drilldown">none</option>
        <option name="percentagesRow">false</option>
        <option name="refresh.display">progressbar</option>
        <option name="rowNumbers">false</option>
        <option name="wrap">true</option>
      </table>
    </panel>
  </row>
  <row>
    <panel>
      <title>Option 3 : addtotals command</title>
      <table>
        <search>
          <query>index=_internal sourcetype=splunkd
| stats count by component
| sort - count 
| head 10
| addtotals row=f col=t labelfield=component label=Total</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
        </search>
        <option name="count">20</option>
        <option name="dataOverlayMode">none</option>
        <option name="drilldown">none</option>
        <option name="percentagesRow">false</option>
        <option name="refresh.display">progressbar</option>
        <option name="rowNumbers">false</option>
        <option name="wrap">true</option>
      </table>
    </panel>
  </row>
</dashboard>
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

0 Karma

niketn
Legend

@khanlarloo, you have following options

Option 1: Use addcoltotals command to calculate column total

<YourBaseSearchWithIndexAndSourcetype> host="splunk.local"
| addcoltotals labelfield=event label=Total

PS: Since you are not showing _time in your stats I don't think you need |bucket _time span=1mon, and in case you do, timechart would be a better command
Option 2: Use addtotals command to calculate column total using row=f col=t

<YourBaseSearchWithIndexAndSourcetype> host="splunk.local"
| addcoltotals row=f col=t labelfield=event label=Total

Option 3: If you are on Splunk 6.5 or greater you can use Simple XML Chart configuration option totalsRow set to true

    <option name="totalsRow">true</option>

Following is a run anywhere dashboard based on Splunk _internal index which elaborates all three options:

<dashboard>
  <label>Total Of Field values</label>
  <row>
    <panel>
      <title>Option 1 : SimpleXML option totalsRow = true</title>
      <table>
        <search>
          <query>index=_internal sourcetype=splunkd
| stats count by component
| sort - count 
| head 10
</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
        </search>
        <option name="count">20</option>
        <option name="dataOverlayMode">none</option>
        <option name="drilldown">none</option>
        <option name="percentagesRow">false</option>
        <option name="rowNumbers">false</option>
        <option name="totalsRow">true</option>
        <option name="wrap">true</option>
      </table>
    </panel>
  </row>
  <row>
    <panel>
      <title>Option 2 : addcoltotals command</title>
      <table>
        <search>
          <query>index=_internal sourcetype=splunkd
| stats count by component
| sort - count 
| head 10
| addcoltotals labelfield=component label=Total</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
        </search>
        <option name="count">20</option>
        <option name="dataOverlayMode">none</option>
        <option name="drilldown">none</option>
        <option name="percentagesRow">false</option>
        <option name="refresh.display">progressbar</option>
        <option name="rowNumbers">false</option>
        <option name="wrap">true</option>
      </table>
    </panel>
  </row>
  <row>
    <panel>
      <title>Option 3 : addtotals command</title>
      <table>
        <search>
          <query>index=_internal sourcetype=splunkd
| stats count by component
| sort - count 
| head 10
| addtotals row=f col=t labelfield=component label=Total</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
        </search>
        <option name="count">20</option>
        <option name="dataOverlayMode">none</option>
        <option name="drilldown">none</option>
        <option name="percentagesRow">false</option>
        <option name="refresh.display">progressbar</option>
        <option name="rowNumbers">false</option>
        <option name="wrap">true</option>
      </table>
    </panel>
  </row>
</dashboard>
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

khanlarloo
Explorer

tanx for your reply i do it and it works.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

SOK it to Me: Top 3 Benefits of Using Splunk Operator on Kubernetes that’ll Make ...

    Thursday, July 9, 2026  |  11:00AM–12:00PM PDT Duration: 1 hour (includes Q&A) Managing can feel like a ...

Upgrade Prep for 10.4, Network Observability Deep Dives, and More from Splunk Lantern

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

Splunk Developer Day announcements: AI agents, MCP tools, Forecasting, and Custom ...

Splunk Developer Day was packed with product and platform updates for developers building in the AI ...