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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Introduction to Splunk AI

How are you using AI in Splunk? Whether you see AI as a threat or opportunity, AI is here to stay. Lucky for ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...

Maximizing the Value of Splunk ES 8.x

Splunk Enterprise Security (ES) continues to be a leader in the Gartner Magic Quadrant, reflecting its pivotal ...