Splunk Search

How to use a timechart to get an average count of monthly sales?

zacksoft
Contributor

I want to use a timechart to get an average count of monthly sales.
But when I use span=30d it calculates average of 30 days from the current day. So, if I am running the query in the middle of the month it calculates average 15 days of the current month and 15 days of the previous month.

But I don't want that.
I want it to be a monthly average calculation like for whole of Jan or whole of Feb ...etc...

| timechart span=1d eval(round(avg(sales),2)) as avgSales
0 Karma
1 Solution

thambisetty
SplunkTrust
SplunkTrust

Hi,

try something like below,

index=_internal host=splunk-test  sourcetype=splunkd count=*
| timechart span=1mon avg(count)

It gives average of count for every month.

————————————
If this helps, give a like below.

View solution in original post

0 Karma

thambisetty
SplunkTrust
SplunkTrust

Hi,

try something like below,

index=_internal host=splunk-test  sourcetype=splunkd count=*
| timechart span=1mon avg(count)

It gives average of count for every month.

————————————
If this helps, give a like below.
0 Karma

niketn
Legend

@zacksoft refer to one of my older answers. This answer does Week by Week calculation, but you can adjust the same approach for Month on Month. https://answers.splunk.com/answers/637244/time-range-to-display-count-of-weekly.html

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

thambisetty
SplunkTrust
SplunkTrust

what is the time range you are taking from time picker?
span will split from the time chosen from time picker. so, if you chose the correct month in time picker, you will see average for the chosen month.

————————————
If this helps, give a like below.
0 Karma

zacksoft
Contributor

I am choosing from last 2 years till Now.

0 Karma

thambisetty
SplunkTrust
SplunkTrust

try span=1mon

————————————
If this helps, give a like below.
0 Karma

zacksoft
Contributor

If I choose span=1mon, and today is 27th July. Will it calculate avg between 1st Jul to 27th July and June-1 to 30 and May 1to 31st and April 1st to 30th etc............ ?

0 Karma

thambisetty
SplunkTrust
SplunkTrust

exactly. that's correct

————————————
If this helps, give a like below.
0 Karma

zacksoft
Contributor

Thank you.

0 Karma
Get Updates on the Splunk Community!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...