Splunk Search

Group results by rows and columns

kent_farries
Path Finder

I need some help grouping and transposing some data. The search below gives me the data but now I want to group it and transpose one of the fields with it's data.
....
| stats count by Stage, Model,Region
| table Region,Model,Stage,count
| sort Region,Model,Stage

Region | Model | Stage | count
East | Blue | Phase1 | 5
East | Blue | Phase2 | 3
East | Red | Phase1 | 2
East | Red | Phase2 | 7
West | Blue | Phase1 | 6
West | Blue | Phase2 | 9
West | Red | Phase1 | 7
West | Red | Phase2 | 8

I want it to look like
Region | Model | Phase1 | Phase2
East | Blue | 5 | 3
........| Red | 2 | 7
West | Blue | 6 |9
........ | Red | 7 | 8

Sorry for my table formatting as I was sure how to do it nicely.

Tags (1)
0 Karma
1 Solution

cmerriman
Super Champion

something like this should help if added to the end:

...|eval{Stage}='count'|fields - Stage count|stats values(*) as * by Region Model

View solution in original post

0 Karma

cmerriman
Super Champion

something like this should help if added to the end:

...|eval{Stage}='count'|fields - Stage count|stats values(*) as * by Region Model

0 Karma

kent_farries
Path Finder

Thank you, that did the trick and saved me a bunch of time. I will add this to my toolbox of SPL.

0 Karma

woodcock
Esteemed Legend

Just add this to the bottom:

| stats list(*) AS * BY Region
0 Karma

kent_farries
Path Finder

Thanks for the suggestion, while this produced the results it did not transpose the columns.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...