Splunk Search

Calculating a ratio of distinct counts in a timechart

emmby
Engager

I have series of events with user ids in them. I would like to calculate the ratio of distinct user ids for events that have a type of X vs. the distinct user ids for events that have a type of Y, in a timechart over time grouped by a different field.

What would be the right way to do this?

0 Karma

musskopf
Builder

Would something like this give you results close to what you're after?

index=main "blabla" | eval typeX=IF(userType="X",1,0) | eval typeY=IF(userType="Y",1,0) | timechart sum(typeX), sum(typeY) by state

0 Karma

somesoni2
Revered Legend

Something like this?

index=blaw sourcetype=blaw type=X OR type=Y | bucket span=SpanOfYourChoice _time | stats count by _time, type, userId | timechart span=SpanOfYourChoice dc(eval(type="X")) as Xcount dc(eval(type="Y")) as Ycount | eval XYratio=Xcount/Ycount | table _time, XYratio
0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...