Splunk Search

how to transpose 2 column

kennethyeung
New Member

......||addcoltotals | table * | reverse | head 1
1_Ausgust_R, 2_Ausgust_R ,1_Ausgust_L,2_Ausgust_L
26 30 15 27

want to have table like below

Date Number1 Number 2
1_August, 26 15
2_August, 30 27

Tags (1)
0 Karma
1 Solution

HiroshiSatoh
Champion

Sorry I did not notice the previous question.
Try this!

......|addcoltotals | table * | reverse | head 1 
|transpose|rename column as Date,"row 1" as Number
|eval key=if(substr(Date,len(Date),1)="L","Number2","Number1")
|eval Date=substr(Date,1,len(Date)-2)
|stats sum(eval(if(key="Number1",Number,0))) as Number1,sum(eval(if(key="Number2",Number,0))) as Number2 by Date

View solution in original post

0 Karma

DalJeanis
Legend

Try this...

| makeresults | eval 1_Ausgust_R=26 | eval 2_Ausgust_R=30 | eval 1_Ausgust_L=15| eval 2_Ausgust_L=27
| rename COMMENT as "The above generates your test data."

| streamstats count as recno
| untable recno myfield myvalue
| rex field=myfield "^(?<Date>\d+_[^_]+)_(?<which>R|L)$"
| eval Number1=case(which="R",myvalue) 
| eval Number2=case(which="L",myvalue)
| stats values(Date) as Date values(Number*) as Number* by recno
| fields - recno
0 Karma

HiroshiSatoh
Champion

Sorry I did not notice the previous question.
Try this!

......|addcoltotals | table * | reverse | head 1 
|transpose|rename column as Date,"row 1" as Number
|eval key=if(substr(Date,len(Date),1)="L","Number2","Number1")
|eval Date=substr(Date,1,len(Date)-2)
|stats sum(eval(if(key="Number1",Number,0))) as Number1,sum(eval(if(key="Number2",Number,0))) as Number2 by Date
0 Karma

kennethyeung
New Member

Thanks, it works

0 Karma
Get Updates on the Splunk Community!

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...

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

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...