Splunk Search

Why is stats count query not working as expected?

PaulaCom
Path Finder

Hi All 

I have a csv file in splunk that i am searching on

i am looking to get the total monthly figure spend on each account number and then the total spend per month (of all account number) 

Here my query i've created 

..... main search 
| rename Order_Date as Month
| stats count by Account_Number, Total_Sum, Month
| eventstats sum(Total_Sum) as Monthly_Total by Month
| sort - Total_Sum
| sort Account_Number
| stats list(Account_Number) as Account_Number, list(Total_Sum) as Total_Sum, values(Monthly_Total) as Monthly_Total by Month

it looks good but then i noticed that i haven't added each Account_Number up per month (see table below as 6210 appears 3 times.  Can anyone help? 

Month Account_Number Total_Sum Monthly_Total

April
5751
5756
6201
6203
6205
6210
6210
6210
6340
1986
23423.42
139
17003.09
7107.98
1395.12
50
18
8.05
51130.66

 

Also i'd like to make the figures in Euros

I've tried below but it wont work - any ideas 
| fieldformat Total="€".tostring(Total, "commas")

finally Splunk has put the month April at the top, i've tried to use the eval command to move January to the top using below code but this hasn't helped - any ideas? 

| eval M=case(Month=="April","04", Month=="January","01", Month=="February", "02", Month=="March","03", Month=="May", "05", Month=="June", "06", Month=="July","07", Month=="August","08", Month=="September", "09")
| sort M
| fields - M

 

Many thanks

 

Labels (5)
Tags (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The Account_Number values are repeated because they are repeated in the data.  That's the nature of the list function.  To show unique values, use the values function.

... main search 
| rename Order_Date as Month
| stats count by Account_Number, Total_Sum, Month
| eventstats sum(Total_Sum) as Monthly_Total by Month
| sort - Total_Sum
| sort Account_Number
| stats values(Account_Number) as Account_Number, list(Total_Sum) as Total_Sum, values(Monthly_Total) as Monthly_Total by Month

You didn't what "it wont work" means, but I suspect the fieldformat command is failing because the Total field doesn't exist.

The eval trick to sort fields as desired is a proven method, but how well it works depends on where it's placed in the query.  Please show the full query with the code that "hasn't helped".

---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Get ready to show some Splunk Certification swagger at .conf24!

Dive into the deep end of data by earning a Splunk Certification at .conf24. We're enticing you again this ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Now On-Demand Join us to learn more about how you can leverage Service Level Objectives (SLOs) and the new ...

Database Performance Sidebar Panel Now on APM Database Query Performance & Service ...

We’ve streamlined the troubleshooting experience for database-related service issues by adding a database ...