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
Influencer

@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
Influencer

@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

 

Get Updates on the Splunk Community!

Splunk Observability Cloud's AI Assistant in Action Series: Auditing Compliance and ...

This is the third post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

What You Read The Most: Splunk Lantern’s Most Popular Articles!

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...