Skip to content
SPL // Splunk

Using the addcoltotals Command

KGI Avatar
 

Written by: Steve Bowser | Last Updated:

 
June 26, 2024
 
 
 

Originally Published:

 
June 26, 2024

There are times when a report is more valuable when columns of numeric data include a “total” entry, such as you might find in a spreadsheet, report, or invoice. The Splunk addcoltotals command provides the ability to easily include this summation in search results. In this article, we’ll investigate the use of the addcoltotals command and provide some examples of its use.

Understanding the addcoltotals Command

As the name of the command implies, this command simply adds up the numerical value total of a selected column. This can be used for a single or multi-value numerical result, and it is as easy as adding the following syntax | addcoltotals to the end of a command with columns with numeric data in them.

Some of the Benefits that addcoltotals can Provide
  • Save time and effort: The command saves time and effort by automatically adding total of a selected column, eliminating the need to manually calculate.
  • Customizable: By default, the label for the totals row will be “Total,” but the command allows users to choose the columns they want to add totals for, as well as customize the label for the summation.

Sample Use Cases

As previously mentioned, the addcoltotals Splunk command organizes numeric data and is simplistic in its use. Consider the following search that will track transaction failures by a cellular carrier:

				
					sourcetype="mint:network" statusCode>200 failed=true | stats count AS Failures BY carrier
				
			

The results of the query produce the following dataset:

carrierFailures
AT&T488
Sprint341
T-Mobile562
Verizon350
By adding | addcoltotals at the end of the command, the total number of failures is easily recognized as you can see in the table below.
				
					sourcetype="mint:network" statusCode>200 failed=true | stats count AS Failures BY carrier | addcoltotals
				
			
carrierFailures
AT&T488
Sprint341
T-Mobile562
Verizon350
1746

Now someone who uses this report will recognize the total number of failures that customers are experiencing over all cellular carriers.

Searches with more than one numerical column, addcoltotals will sum both columns. As and example, let’s take a look at the following search:

				
					sourcetype="mint:network" statusCode=*| stats count(eval(match(failed,"False"))) AS Successes, count(eval(match(failed,"True"))) AS Failures BY carrier | addcoltotals
				
			
carrierSuccessesFailures
AT&T608721
Sprint430457
T-Mobile663865
Unknown8710
Verizon484473
30562516
These search results total the successes and failures of sales transactions per carrier.  In addition, there is also an option to create a label for the totals. Adding the qualifier labelfield= will accomplish this:
				
					sourcetype="mint:network" statusCode=*| stats count(eval(match(failed,"False"))) AS Successes, count(eval(match(failed,"True"))) AS Failures BY carrier| addcoltotals labelfield="Total Failures"
				
			
carrierSuccessesFailuresTotal Failures
AT&T608721
Sprint430457
T-Mobile663865
Unknown8710
Verizon484473
30562516Total

Conclusion

In summary, the addcoltotals command is a powerful command in Splunk that allows users to add up the total of a column or columns quickly and easily. Its functionality enhances the capabilities of Splunk, making it an indispensable tool for companies that rely on data-driven insights to drive success.

To access more Splunk searches, check out Atlas Search Library, which is part of the Atlas Platform. Specifically, Atlas Search Library offers a curated list of optimized searches. These searches empower Splunk users without requiring SPL knowledge. Furthermore, you can create, customize, and maintain your own search library. By doing so, you ensure your users get the most from using Splunk.

Atlas Search Library
Helpful? Don't forget to share this post!
LinkedIn
Reddit
Email
Facebook