Hello Everyone!
I have an output in the below format and would like to filter the duplicate ids with 'fieldA' value as zero then calculate 'fieldA' in the place of zeros
Current Output: filtered Outpt: Required Output
id fieldA id fieldA id fieldA
101 54236.0100 101 54236.0100 101 54236.0100
101 4526441.012 101 4526441.012 101 4526441.012
102 0 102 0 102 fieldB-fieldC
103 4479652.2456 103 4479652.2456 103 4479652.2456
103 0 103 0 103 fieldB-fieldC
104 476526 104 476526 104 476526
105 0 105 0 105 fieldB-fieldC
105 0
I have tried various stats commands but was not able to achieve this.
Can you please help me on how to get the required output?
Thank you in advance
Hello All,
May I please whether we have a way to achieve the required output?
Current Output: filtered Outpt: Required Output
id fieldA id fieldA id fieldA
101 54236.0100 101 54236.0100 101 54236.0100
101 4526441.012 101 4526441.012 101 4526441.012
102 0 102 0 102 fieldB-fieldC
103 4479652.2456 103 4479652.2456 103 4479652.2456
103 0 103 0 104 476526
104 476526 104 476526 105 fieldB-fieldC
105 0 105 0
105 0
Hi
Please try this.
| makeresults
| eval _raw = "id, fieldA
101,54236.0100
101,4526441.012
102,0
103,4479652.2456
103,0,0
104,476526
105,0
105,0"
| multikv forceheader=1
| rename COMMENT as "Previous generate sampe, next is the logic"
| dedup id, fieldA
| eval fieldA = if (like(fieldA, "0"), "fieldB-fieldC", fieldA)
| table field id fieldA
And if those fields B and C are numeric then remove " around those in eval + if.
Also like(fieldA.... should replaced to normal numeric comparison if it is numeric instead of character field.
r. Ismo
r. Ismo
Hello @isoutamo ,
Thank you:) This worked perfectly for my requirement:) The 'fieldB' and 'feildC' are numeric.
Can you please let me know how to modify for the below required Output?
Current Output: filtered Outpt: Required Output
id fieldA id fieldA id fieldA
101 54236.0100 101 54236.0100 101 54236.0100
101 4526441.012 101 4526441.012 101 4526441.012
102 0 102 0 102 fieldB-fieldC
103 4479652.2456 103 4479652.2456 103 4479652.2456
103 0 103 0 104 476526
104 476526 104 476526 105 fieldB-fieldC
105 0 105 0
105 0
Thank you in advance
-- your search
| stats values(fieldA) as fieldA values(fieldB) as fieldB values(fieldC) as fieldC by Id
| mvexpand fieldA
| eval fieldA=if(fieldA=0, fieldB-fieldC, fieldA)
This only works if fieldB and fieldC are unique for Id i.e. the stats doesn't create a multi-value field
Hello @ITWhisperer ,
Thank you:) This snippet works correctly. But I have a different required output now.
Current Output: filtered Outpt: Required Output
id fieldA id fieldA id fieldA
101 54236.0100 101 54236.0100 101 54236.0100
101 4526441.012 101 4526441.012 101 4526441.012
102 0 102 0 102 fieldB-fieldC
103 4479652.2456 103 4479652.2456 103 4479652.2456
103 0 103 0 104 476526
104 476526 104 476526 105 fieldB-fieldC
105 0 105 0
105 0
Can you please let me know how to get the Required Output?
Thank you in advance
From your very limited sample data it appears that for any given Id, fieldA is either a non-zero number or zero or both, with the assumption that for any given Id, there will be at most one non-zero number and any number of zeroes including none. Also, I assume fieldB and fieldC are unique for any given Id. If this is true, then try this
-- your search
| stats sum(fieldA) as fieldA values(fieldB) as fieldB values(fieldC) as fieldC by Id
| eval fieldA=if(fieldA=0, fieldB-fieldC, fieldA)
Hello @ITWhisperer ,
This sums up the 'feildA' even when we have values greater than zero. But I want them separately.
For example : id 101 in the above example.
-- your search
| eventstats max(fieldA) as maxA by Id
| eval fieldA=if(fieldA=0, if(maxA=0, fieldB-fieldC, null()), fieldA)
| where isnotnull(fieldA)
| fields - maxA