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
Get Updates on the Splunk Community!

Upcoming Webinar: Unmasking Insider Threats with Slunk Enterprise Security’s UEBA

Join us on Wed, Dec 10. at 10AM PST / 1PM EST for a live webinar and demo with Splunk experts! Discover how ...

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...