Question

Imagine I have a table like this :

month-year varchar
nbr integer

values :

[01-2014,5],[02-2014,110],[03-2014,154],[04-2014,110]

Imagine we are the 15th of april. This datas are displayed on a linear graph. If I display the real value for the month of april the line will be down. What I would like is to display the trend rather than the real value for the current month.

I tought about doing something like this :

(5+110+154+110) / (3 + (15/30.5)) = 108

Where "3" is the number of month passed, "30.5" is the average number of days by month, and "15" is the number of days passed for the current month. This is wrong because it's lower than the real value.

I'm pretty sure there is a more formal way to do this, but as you can see I don't know a lot about statistics and trends. I tought about other ways but they are not very convincing.

Can you help me ?

NB: in reality I can get the count number by day, even by hours or minutes. I just count in mysql the number of entries and I have a date-time column. I described the table with month and year in order to make myself clear for the purpose of this example.

Was it helpful?

Solution

What you are trying to calculate is called a moving average.

You have a slight bug in your calculation. The formula should be:

(5+110+154+110) / (3 + (15/30.5))
                        ^^^^^^^

You need to decide how many months back to include in your moving average.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top