Other Usage

How to group by multiple fields?

Leo_Pegasus
New Member
 

I have following splunk fields

Date,Group,State 

State can have following values InProgress|Declined|Submitted

I like to get following result

Date.          Group. TotalInProgress.  TotalDeclined TotalSubmitted. Total
-----------------------------------------------------------------------------     
12-12-2021       A.     13.              10               15           38

I couldn't figured it out. Any help would be appreciated

Labels (1)
Tags (3)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You need to concatenate the fields, do the stats (well chart to be precise), then split the concatenated field

| makeresults count=100
| eval date=strftime(relative_time(now(),"-".(random()%10)."d@d"),"%F")
| eval group=mvindex(split("ABC",""),random()%3)
| eval state=mvindex(split("InProgress|Declined|Submitted","|"),random()%3)



| eval dategroup=date."|".group
| chart count by dategroup state
| addtotals
| eval date=mvindex(split(dategroup,"|"),0)
| eval group=mvindex(split(dategroup,"|"),1)
| fields - dategroup
| table date group * Total
0 Karma

bowesmana
SplunkTrust
SplunkTrust

Edited: Bad first response. You can do this with two stats 

 

your_search
| stats count by Date Group State
| eval "Total{State}"=count
| fields - State count
| stats values(*) as * by Date Group
| addtotals

 

 

0 Karma
Get Updates on the Splunk Community!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...