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!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...