Splunk Search

Cab a field be used in stats command that's declared in eval command?

gokikrishnan
New Member

BaseSearch>|convert auto(A)|appendcols[|convert auto(B)]|eval C=A-B|table A B C
This gives the result as
A B C
5 7 12
Currently i want the result like as follows
TestField A B
Test1 1 2
Test2 4 5

How do i write a query to get the above result? I have tried the following things.
1) I have tried to group by TestField in a table
2) Tried converting the C to string again as it can be used in stats command again.

Request you to assist me with regard to the same.

Tags (1)
0 Karma
1 Solution

renjith_nair
Legend

@gokikrishnan,
Not sure whether understand you correctly, but based on your inputs, this should give you the expected result

Your current search to get TF,C,B,A|replace TF* with T* in TF|table TF,C,B
Happy Splunking!

View solution in original post

0 Karma

woodcock
Esteemed Legend

Your descriptions (I have read all of them) make no sense at all. Show is some sample events, show us a mockup of the desired final output and THEN try to explain the steps required to get from data to final output.

0 Karma

renjith_nair
Legend

@gokikrishnan,
Not sure whether understand you correctly, but based on your inputs, this should give you the expected result

Your current search to get TF,C,B,A|replace TF* with T* in TF|table TF,C,B
Happy Splunking!
0 Karma

gokikrishnan
New Member

I got answer for the same. Thanks Renjith and All.

0 Karma

DalJeanis
Legend

@gokikrishnan - We converted the apparently correct comment to an answer. Please accept the answer if that is what got you your solution. If not, then please post your own solution, so that others may benefit, and accept your own answer. Thanks!

0 Karma

gokikrishnan
New Member

Let me explain again clearly,

TFN=Test Field Name, TFE1=TestFieldEntry, TFE2=TestFieldEntry,
C=Field found out from Eval, A=Count of values that is found with based on available fields, B=Count of values that is found with based on available fields. TF has two types of entries. They are TF1 and TF2 respectively.

C is calculated like C=A-B. Used the below query.

|convert auto(A)|appendcols[|convert auto(B)]|eval C=A-B|table A B C
With the above query, I am getting the below result as follows.
C B A
4 5 9

I need to get the values of C and B using the by clause grouped by TFN to get the result in the following manner.
TFN C B
TFE1 1 2
TFE2 4 5

Please tell me whether you understand this explanation.

0 Karma

renjith_nair
Legend

@gokikrishnan, trying to understand your requirement in bit more detail

The first result looks like A+B and not A-B.
Do you want to convert the first result to second result or do you have already some events which we can look at?
Please provide some sample events and the expected output

Happy Splunking!
0 Karma

gokikrishnan
New Member

My Bad, Gave the requirement incorrectly. Sorry.
Here A is Total, I have found B. To find C, I do C=A-B, As of now I am able to get the result as follows:
TF C B A
TF1 1 2 3
TF2 4 5 9
Actually need the query to be displayed as follows:
TF C B
T1 1 2
T2 4 5

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...