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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...