Splunk Search

Need help with a search with join, append or appendcols

tungpx
Explorer

Hello, I need help with a search query, that at first seem easy but suprising difficult to execute. I have a money transaction db between 2 person, now I have to find which person send out more money than they receive, and output all of their transaction (both send and receive). 

My query is like so 

 

index=myindex 
|eventstats sum(AMOUNT) as total_sent by ACCOUNT_FROM
|eval temp=ACCOUNT_FROM
|table _time ACCOUNT_TO ACCOUNT_FROM TRACE total_sent INFO temp
|join type=inner temp
[search index=myindex
|stats sum(AMOUNT) as total_received by ACCOUNT_TO
|eval temp=ACCOUNT_TO] 
|where total_sent > total_receive 

 

This query only produce the transaction at which that account sending out but not the transaction that that account receive. How do I go about this. I'm thinking about output the temp as an csv and inputlookup again in the db.

Labels (1)
0 Karma

NevilleRadcliff
Loves-to-Learn

Try using eventstats instead of join to keep both sent and received transactions. coalesce helps handle null values. This approach avoids lookup and maintains full data visibility while ensuring the correct filtering of accounts. I work in an animation studio, and transferring large video files was always a challenge. We tried cloud storage, but it was slow and required sign-ups. Filemail solved all our problems—it’s fast, secure, and lets us send huge files without forcing the recipient to create an account. If you’re in the creative industry, this is a must-have!

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| eventstats sum(AMOUNT) as total_sent by ACCOUNT_FROM
| eventstats sum(AMOUNT) as total_received by ACCOUNT_TO
| table _time ACCOUNT_TO ACCOUNT_FROM TRACE total_sent total_received INFO AMOUNT
| where total_sent > total_received
0 Karma

tungpx
Explorer

But it doesn't right, does it?
Your query produce total_sent is for ACCOUNT_FROM, and total_received is for ACCOUNT_TO. Since ACCOUNT_FROM and ACCOUNT_TO are two different person then where total_sent > total_received is not make sense. 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You are right - I misunderstood what you were trying to do - try this

| eval row=mvrange(0,2) 
| mvexpand row
| eval sent=if(row=0,AMOUNT,null())
| eval received=if(row=1,AMOUNT,null())
| eval account=if(row=0,ACCOUNT_FROM,ACCOUNT_TO)
| eventstats sum(sent) as total_sent sum(received) as total_received by account
| fillnull value=0 total_sent total_received
| where total_sent > total_received

tungpx
Explorer

What if I want to add the requirement that the amount received have to be above 250 and the number of reviced transaction have to be above 10.  The original query is

index=myindex AMOUNT>=250
|eventstats sum(AMOUNT) as total_sent count as receive by ACCOUNT_FROM
|eval temp=ACCOUNT_FROM
|where receive >10
|table _time ACCOUNT_TO ACCOUNT_FROM TRACE total_sent INFO temp
|join type=inner temp
[search index=myindex
|stats sum(AMOUNT) as total_received by ACCOUNT_TO
|eval temp=ACCOUNT_TO] 
|where total_sent > total_receive 
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| eval row=mvrange(0,2) 
| mvexpand row
| eval sent=if(row=0,AMOUNT,null())
| where isnull(sent) OR sent>=250
| eval received=if(row=1,AMOUNT,null())
| eval account=if(row=0,ACCOUNT_FROM,ACCOUNT_TO)
| eventstats sum(sent) as total_sent sum(received) as total_received count(received) as count by account
| fillnull value=0 total_sent total_received
| where total_sent > total_received AND count > 10
0 Karma
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!

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...