Splunk Search

Sum of Multivalue (list) Items

OliverG91
Explorer

Given this search result:
Company A         Visa            15
                                 MC                5
                                 AmEx           2
Company B         Visa            19
                                 MC                8
                                 AmEx           3

How can I generate a total row like this?
Total                      Visa            34
                                 MC             13
                                 AmEx           5

Labels (1)
0 Karma
1 Solution

livehybrid
SplunkTrust
SplunkTrust

Hi @OliverG91 

You could try something like this, but its based on very little info - might work though!

adjust the type,count to whatever your two fields with that data is called.

| eval vals=mvzip(type,count)
| mvexpand vals
| makemv vals delim=","
| eval cardType=mvindex(vals,0), count=mvindex(vals,1)
| stats sum(count) as count by cardType

livehybrid_0-1752677178386.png

 

🌟 Did this answer help you? If so, please consider:

  • Adding karma to show it was useful
  • Marking it as the solution if it resolved your issue
  • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing

View solution in original post

livehybrid
SplunkTrust
SplunkTrust

Hi @OliverG91 

You could try something like this, but its based on very little info - might work though!

adjust the type,count to whatever your two fields with that data is called.

| eval vals=mvzip(type,count)
| mvexpand vals
| makemv vals delim=","
| eval cardType=mvindex(vals,0), count=mvindex(vals,1)
| stats sum(count) as count by cardType

livehybrid_0-1752677178386.png

 

🌟 Did this answer help you? If so, please consider:

  • Adding karma to show it was useful
  • Marking it as the solution if it resolved your issue
  • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing

OliverG91
Explorer

I had to reformat your solution and plugged it in " | appendpipe" (appended from my  main search):
| appendpipe [eval vals=mvzip(card_type,card_count) | mvexpand vals | makemv vals delim="," | eval card_type=mvindex(vals,0), card_count=mvindex(vals,1) | stats sum(card_count) AS card_count BY card_type | eval company_name="TOTAL" | stats list(card_type) AS card_type, list(card_count) AS card_type BY company_name]

and it seemed to work! Thank you for this

0 Karma

livehybrid
SplunkTrust
SplunkTrust

Hi,

Can you tell me what this looks like as events, or how you got to them? Are the card types and counts a list generated from stats?

🌟 Did this answer help you? If so, please consider:

  • Adding karma to show it was useful
  • Marking it as the solution if it resolved your issue
  • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing

0 Karma

OliverG91
Explorer

The query used to obtain the above result is something like this:
[mainsearch]

| stats count as card_count BY company_name, card_type

| stats list(card_type) AS card_type, list(card_count) AS card_count BY company_name

I'm looking to add a totals row with the details shown above

 

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...