Splunk Search

How to construct columns with the same data, and then use these pseudo columns to calculate

flzhang132
Explorer

I want to get data ,as following
alt text

How to construct columns with the same data, and then use these pseudo columns to calculate in splunk ?

Tags (2)
0 Karma
1 Solution

adonio
Ultra Champion

hello there,

here is an example with search and eval

... search that captures fields project and pfee ...
| eventstats sum(pfee) as total 
| table project pfee 
| eventstats sum(pfee) as total
| eval other = if(project="other",pfee,null())
| eventstats max(other) as other
| eval total_minus_other = total - other
| eval ratio = round(pfee/total_minus_other, 2)
| eval pfee_plus_pfee_times_ratio = pfee + pfee*ratio

here is a sample to run anywhere:

| makeresults count=1 
| eval data = "p1,1;p2,2;p3,3;p4,10;p5,20;other,30"
| makemv delim=";" data
| mvexpand data
| rex field=data "(?<project>\S+)\,(?<pfee>\d{1,5})"
| table project pfee
| eventstats sum(pfee) as total
| eval other = if(project="other",pfee,null())
| eventstats max(other) as other
| eval total_minus_other = total - other
| eval ratio = round(pfee/total_minus_other, 2)
| eval pfee_plus_pfee_times_ratio = pfee + pfee*ratio

hope it helps

View solution in original post

0 Karma

adonio
Ultra Champion

hello there,

here is an example with search and eval

... search that captures fields project and pfee ...
| eventstats sum(pfee) as total 
| table project pfee 
| eventstats sum(pfee) as total
| eval other = if(project="other",pfee,null())
| eventstats max(other) as other
| eval total_minus_other = total - other
| eval ratio = round(pfee/total_minus_other, 2)
| eval pfee_plus_pfee_times_ratio = pfee + pfee*ratio

here is a sample to run anywhere:

| makeresults count=1 
| eval data = "p1,1;p2,2;p3,3;p4,10;p5,20;other,30"
| makemv delim=";" data
| mvexpand data
| rex field=data "(?<project>\S+)\,(?<pfee>\d{1,5})"
| table project pfee
| eventstats sum(pfee) as total
| eval other = if(project="other",pfee,null())
| eventstats max(other) as other
| eval total_minus_other = total - other
| eval ratio = round(pfee/total_minus_other, 2)
| eval pfee_plus_pfee_times_ratio = pfee + pfee*ratio

hope it helps

0 Karma

flzhang132
Explorer

you are great , thank you very much

0 Karma

kmorris_splunk
Splunk Employee
Splunk Employee

Can you clarify which fields exists already, and which fields you are trying to construct?

0 Karma
Get Updates on the Splunk Community!

Operationalizing TDIR: Building a More Resilient, Scalable SOC

Optimizing SOC workflows with a unified, risk-based approach to Threat Detection, Investigation, and Response ...

Pro Tips for First-Time .conf Attendees: Advice from SplunkTrust

Heading to your first .Conf? You’re in for an unforgettable ride — learning, networking, swag collecting, ...

Raise Your Skills at the .conf25 Builder Bar: Your Splunk Developer Destination

Calling all Splunk developers, custom SPL builders, dashboarders, and Splunkbase app creators – the Builder ...