Splunk Search

How to rearrange table by values in a column

andrewhlui
Explorer

So I have the following data as output statistics from a search:

User      Group         Number
Andy          A            123
Andy          B            123
Andy          C            123
Bob           A            123
Bob           B            123
Cam           A            123
Cam           B            123
Cam           C            123

How can I rearrange it so that it becomes:

User         A         B        C
Andy       123       123      123
Bob        123       123        0
Cam        123       123      123

Also, what is this rearranging called?

0 Karma
1 Solution

andrewhlui
Explorer

Never mind, I figured out an answer:

... | xyseries User, Group, Number

View solution in original post

0 Karma

abalogh_splunk
Splunk Employee
Splunk Employee

Hi,

There is a command called transpose.

http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Transpose

Try it out with DalJeanis example:

| makeresults
| eval User="Andy Bob Cam", Group="A B C"
| makemv User
| mvexpand User
| makemv Group
| mvexpand Group
| Where NOT (Group="C" AND User="Bob")
| eval Number = 123
| rename COMMENT as "the above just enters your test data"
| chart sum(Number) over User by Group
| transpose

0 Karma

DalJeanis
Legend

You are looking for the chart command...

| makeresults 
| eval User="Andy Bob Cam", Group="A B C" 
| makemv User 
| mvexpand User 
| makemv Group 
| mvexpand Group 
| Where NOT (Group="C" AND User="Bob") 
| eval Number = 123
| rename COMMENT as "the above just enters your test data"

| chart sum(Number) over User by Group

...and then after you review the above, add this on the end and look at this handy little reverse tool...

| untable User Group Number
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi andrewhlui,
add to your search

| chart sum(Number) AS Number over User BY Group

If you like you can use different functions instead sum.
Bye.
Giuseppe

0 Karma

andrewhlui
Explorer

Never mind, I figured out an answer:

... | xyseries User, Group, Number

0 Karma

DalJeanis
Legend

@andrewhliu - yep, xyseries will work too. Check out the untable command on the results.

We're converting your comment to an answer. Please accept the answer so that the question will show as answered.

0 Karma
Get Updates on the Splunk Community!

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...

Cloud Platform & Enterprise: Classic Dashboard Export Feature Deprecation

As of Splunk Cloud Platform 9.3.2408 and Splunk Enterprise 9.4, classic dashboard export features are now ...