Splunk Search

## How do I combine two fields from different sources but of the same source type in a single search?

New Member

I am trying to perform a ratio calculation on 2 fields (values) coming from different sources but of the same source type, Individually my searches work fine and return the correct values. But, when I combine them together, I get really weird results. Many Thanks for your help !

``````(sourcetype= "test" source=A host =192.168.1.1 fieldA=* ) OR source=B
eval sourceA=round(fieldA/1000),2
eval sourceB=round(fieldB/1000),2
stats max(sourceA) as SA max(sourceB) as SB
|eval percent_ratio=round(SA/SB,2)
|stats max(percent_ratio)
``````

Legend:
fieldA (sourceA),
fieldB (sourceB)

Tags (3)
1 Solution
SplunkTrust

To get the ratio between two maximums your search looks pretty much correct already, I'd just leave off the rounding until the very end.

``````source=A OR source=B
| stats max(fieldA) as maxA max(fieldB) as maxB
| eval percent_ratio = round(maxA/maxB*100, 2)
| fields percent_ratio
``````
SplunkTrust

To get the ratio between two maximums your search looks pretty much correct already, I'd just leave off the rounding until the very end.

``````source=A OR source=B
| stats max(fieldA) as maxA max(fieldB) as maxB
| eval percent_ratio = round(maxA/maxB*100, 2)
| fields percent_ratio
``````
SplunkTrust

If that's the calculation you need, sure.

New Member

Thanks Martin , Appreciate it !

New Member

Appreciated ,
another question if you don't mind , what about
sum & max it shouldn't make no difference , correct ?

source=A OR source=B
| stats sum(fieldA) as sumA max(fieldB) as maxB
| eval percent_ratio = round(sumA/maxB*100, 2)
| fields percent_ratio

SplunkTrust

Can you describe what result you're looking for?

As your search sits now, you're getting the maximums of both values, calculating the ratio of those two maximums, and then getting the maximum of that one ratio. I can't tell from that what you're actually trying to achieve, and in what way your search deviates from that goal.

New Member

I am trying to calculate percent ratio from two max(values) belong to two diff sources and I am looking for the correct syntax on how to do that

dataset from sourceA
fieldA (value)
no fieldB

data set from sourceB
fieldB(value)
no fieldA
it should produce the following results

sourceA(max value) sourceB(max value) percent_ratio
62 200 (200/62)*100

Hope it will clarified your question

Thanks

.conf21 Now Fully Virtual!