Splunk Dev

How to count the number of values in a multivalue field in or with a stats command

rberman
Path Finder

I have the following search query that I've been using so far to display the unique values in lists of Ids:

<search>
| eval ids=if(group_id >= 4, id, '')
| eval type_x_ids=if((group_id >= 4 AND is_type_x="true"), id, '')
| eval non_type_x_ids=if((group_id >= 4 AND is_type_x="false"), id, '')
| stats count as total_count, values(type_x_ids) as list_of_x_ids, values(non_type_x_ids) as list_of_non_x_ids, values(ids) as list_of_all_ids by some_characteristic

Now that I've seen which Ids are in the lists, I would like to change the query to count the number of unique ids in the lists split up by some characteristic. mvcount doesn't seem to work in the stats command the way I tried it:

attempt 1:
| stats count as total_count, mvcount(type_x_ids) as num_of_x_ids, mvcount(non_type_x_ids) as num_of_non_x_ids, mvcount(ids) as num_of_all_ids by some_characteristic

attempt 2:
| stats count as total_count, mvcount(values(type_x_ids)) as num_of_x_ids, mvcount(values(non_type_x_ids)) as num_of_non_x_ids, mvcount(values(ids)) as num_of_all_ids by some_characteristic

How should I write the stats line so I would get a table that shows the number of unique of Ids in each list of Ids split by some characteristic? I would like the following fields in my resulting table:

|  some_characteristic  |  total_count  |  num_of_x_ids  |  num_of_non_x_ids  |  num_of_all_ids  | 

I would appreciate any help you can give!!

0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| stats count as total_count, values(type_x_ids) as list_of_x_ids, dc(type_x_ids) as count_of_x_ids, values(non_type_x_ids) as list_of_non_x_ids, dc(non_type_x_ids) as count_of_non_x_ids, values(ids) as list_of_all_ids, dc(ids) as count_of_all_ids by some_characteristic

View solution in original post

rberman
Path Finder

dc was exactly what I was looking for! Thank you so much!

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| stats count as total_count, values(type_x_ids) as list_of_x_ids, dc(type_x_ids) as count_of_x_ids, values(non_type_x_ids) as list_of_non_x_ids, dc(non_type_x_ids) as count_of_non_x_ids, values(ids) as list_of_all_ids, dc(ids) as count_of_all_ids by some_characteristic
Get Updates on the Splunk Community!

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

What's New in Splunk Observability Cloud and Splunk AppDynamics - May 2025

This month, we’re delivering several new innovations in Splunk Observability Cloud and Splunk AppDynamics ...