Dashboards & Visualizations

Group by multiple attribute and get count per day

anilbabuk
Loves-to-Learn

I have data like below

DateFileUser
1/10/2022F1U1
1/10/2022F1U2
1/10/2022F2U1
1/11/2022F3U3
1/11/2022F1U1
1/11/2022F2U2
1/11/2022F3U3
1/11/2022F1U1
1/12/2022F2U1
1/12/2022F3U2
1/12/2022F1U1
1/12/2022F2U1

 

 

I would like to Group the data with File & user and needs to get count for each per day as below. Please let me know how can I get like this?

 

FileUser1/10/20221/11/20221/12/2022
F1U1121
F2U11 2
F1U21  
F2U2 1 
F3U2  1
F3U3 2 
Labels (1)
0 Karma

a_m_s
Explorer

@anilbabuk 

| eval TT=File."-".User
| fields - File User
| chart count over TT by Date
| eval File=mvindex(split(TT,"-"),0)
| eval User=mvindex(split(TT,"-"),1)
| fields - TT
| table File User *

0 Karma

tscroggins
Champion

@a_m_s 

This works as long as File and User never contain a hyphen. There's no 100% safe method of concatenating and later separating strings for grouping without storing and comparing the original values, but if you understand your dictionary, you can choose values that reduce the probability of a collision. The values provided in the original question may just be examples.

0 Karma

tscroggins
Champion

@anilbabuk 

If you have a data model, you can use the pivot command:

| pivot My_Data_Model My_Dataset count(My_Dataset) SPLITROW File SPLITROW User SPLITCOL Date
| sort User File
| foreach */*/* 
    [ eval <<FIELD>>=nullif('<<FIELD>>', 0) ]

If you do not have a data model, you'll need to manipulate the output of chart, stats, etc. to split columns by multiple row fields:

```base search here```
| stats count by File User Date
| eval {Date}=count
| stats max(*/*/*) as */*/* by File User
| sort User File

 

Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

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

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...