Splunk Search

How to compare 2 different rows using count?

villnooB
Explorer

Hi guys,

Can you please help me , I am trying to create a query in which it shows if a user is in  a different location in the sameday it will only prioritize one of it. please see below

| convert timeformat="%F %H:%M" ctime(zone) as ctime
| stats count by user fullname country ctime location
| rename fullname as "Name", ctime as DateStamp, location as "Location", user as "NetworkID", country as "Country"
| fields - count
| sort 0 NetworkID

This is what i am getting if I'm using the query above

NetworkID Name Country DateStamp Location
userA A Sample Spain 12-26-2022 Office
userA A Sample Spain 12-27-2022 Office
userA A Sample Spain 12-27-2022 Home

 

and this is what I am trying to get that If it's in the same day it will only Select the office

NetworkID Name Country DateStamp Location
userA A Sample Spain 12-26-2022 Office
userA A Sample Spain 12-27-2022 Office

Thank you in advance

Labels (3)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| convert timeformat="%F %H:%M" ctime(zone) as ctime
| stats count values(location) as location by user fullname country ctime
| rename fullname as "Name", ctime as DateStamp, location as "Location", user as "NetworkID", country as "Country"
| fields - count
| eval Location=if(isnotnull(mvfind(Location, "Office")), "Office", "Home")
| sort 0 NetworkID

View solution in original post

villnooB
Explorer

@ITWhisperer , @Manasa_401 , @SanjayReddy 

Thank you very much for the help

Manasa_401
Communicator

Hello @villnooB 

After rename, add the below logic


| eventstats count as multiple by DateStamp Name
| eval valid=if(multiple>1 AND Location="Home","NO","YES")
| search valid="YES"
|fields - count multiple valid

If this helps, karma would be appreciated.

Thanks,

Manasa

ITWhisperer
SplunkTrust
SplunkTrust
| convert timeformat="%F %H:%M" ctime(zone) as ctime
| stats count values(location) as location by user fullname country ctime
| rename fullname as "Name", ctime as DateStamp, location as "Location", user as "NetworkID", country as "Country"
| fields - count
| eval Location=if(isnotnull(mvfind(Location, "Office")), "Office", "Home")
| sort 0 NetworkID

villnooB
Explorer

@ITWhisperer 

Thank you very much

0 Karma

SanjayReddy
SplunkTrust
SplunkTrust

Hi @villnooB 

can you try following qurey, highlight lines are are newly added 

| convert timeformat="%F %H:%M" ctime(zone) as ctime
| stats count by user fullname country ctime location
| eval Filter=if(location="Office","Yes","NO")
| search Filter="Yes"
| rename fullname as "Name", ctime as DateStamp, location as "Location", user as "NetworkID", country as "Country"
| fields - count
| sort 0 NetworkID

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...