Splunk Search

How to de-aggregate the STATS result ?

zacksoft_wf
Contributor

I have this query where I need to use stats to aggregate the results based on account_number.  
Now, some of the results are multivalued. I need the output to be like a table, one values for each row.  like somehow expand the aggregated results into a tabular  format.

=========================================
`index_list` account_type="Service Account"
| addinfo
| eventstats dc(sourcetype) as dc_sourcetype by service_number
| where dc_sourcetype>1
| stats values(is_interactive) as is_interactive,
values(account_name) as account_name,
values(full_name) as full_name,
values(email_address) as email_address,
values(manager_name) as manager_name,
values(service_account_name) as service_account_name,
values(account_type) as account_type,
values(service_account_id) as service_account_id,
values(au_owner_name) as au_owner_name,
values(au_owner_email) as au_owner_email
BY account_number

=======================================

account_type, service_account_id, account_number are multivalue fields.

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

mvexpand will only do one field at a time, if you want to expand multiple multivalue field, I wrote a post about how this might be done back in April https://community.splunk.com/t5/Splunk-Search/mvexpand-limits/m-p/549178 

To be honest, you might be better off modifying the stats command to get what you want in the first place. For example, if account_type, service_account_id, account_number all have values you could do something like this:

`index_list` account_type="Service Account"
| addinfo
| eventstats dc(sourcetype) as dc_sourcetype by service_number
| where dc_sourcetype>1
| stats values(is_interactive) as is_interactive,
values(account_name) as account_name,
values(full_name) as full_name,
values(email_address) as email_address,
values(manager_name) as manager_name,
values(service_account_name) as service_account_name,
values(au_owner_name) as au_owner_name,
values(au_owner_email) as au_owner_email
BY account_type, service_account_id, account_number

 

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

mvexpand will only do one field at a time, if you want to expand multiple multivalue field, I wrote a post about how this might be done back in April https://community.splunk.com/t5/Splunk-Search/mvexpand-limits/m-p/549178 

To be honest, you might be better off modifying the stats command to get what you want in the first place. For example, if account_type, service_account_id, account_number all have values you could do something like this:

`index_list` account_type="Service Account"
| addinfo
| eventstats dc(sourcetype) as dc_sourcetype by service_number
| where dc_sourcetype>1
| stats values(is_interactive) as is_interactive,
values(account_name) as account_name,
values(full_name) as full_name,
values(email_address) as email_address,
values(manager_name) as manager_name,
values(service_account_name) as service_account_name,
values(au_owner_name) as au_owner_name,
values(au_owner_email) as au_owner_email
BY account_type, service_account_id, account_number

 

zacksoft_wf
Contributor

Thank you @ITWhisperer . This greatly helps.  There is just one little issue.
Field like "service_account_id"  also present in events as "src_account_id". They are essentially the same field with different name. And I am thinking  to use coalesce function like,
eval service_account_id = coalesce(service_account_id,src_account_id)

The question that comes to my mind is , this field is also used in stats " BY" clause, now should the coalesce function be used before or after | stats ..BY ...  ?
Not just 'service_Account_id' , the other fields like account_type also has to be used in conjuntion with coalesce as, it has another field with slightly different name and i have to fetch the one that has value and is used in BY clause.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

I would do the coalescing before the stats command - if a field from the by clause is null, the event doesn't get included in the stats

0 Karma

isoutamo
SplunkTrust
SplunkTrust
0 Karma
Get Updates on the Splunk Community!

Index This | What is broken 80% of the time by February?

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

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...