Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Moving average on expression
fporcher
Hi,<br />
<br />
How work moving average :<br />
I've a dataset with 2 col<br />
1st day of month - value<br />
<blockquote class='ipsBlockquote' ><p>
3.0 2006-09-01 00:00:00<br />
81.31667375564575 2006-10-01 00:00:00<br />
240.28496837615967 2006-11-01 00:00:00<br />
41.51111149787903 2006-12-01 00:00:00<br />
31.26666784286499 2007-01-01 00:00:00<br />
...<br />
45.4578113315779 2009-02-01 00:00:00<br /></p></blockquote>
<br />
I want a bar chart <br />
x : date<br />
y : the moving average 12 month past<br />
<br />
<br />
How to write the expression (I'm lost)<br />
<br />
Thanks<br />
F.P.
Find more posts tagged with
Comments
mwilliams
Hi F.P.,
Can you explain this a little more?
fporcher
<blockquote class='ipsBlockquote' data-author="mwilliams"><p>Hi F.P.,<br />
<br />
Can you explain this a little more?</p></blockquote>
<br />
I've one value by Date (1st day of month)<br />
I want draw i.e.<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
2008-03-01 12
2008-02-01 11
2008-01-01 10
2007-12-01 9
2007-11-01 10
2007-10-01 13
2007-09-01 11
2007-08-01 12
2007-07-01 18
2007-06-01 13
2007-05-01 17
2007-04-01 12
2007-03-01 5
2007-02-01 11
2007-01-01 10
</pre>
For 2008-01-01 = sum of (values 2007-01-01 to 2008-01-01) div by 13<br />
(10+9+10+13+11+12+18+13+17+12+5+11+10)/13<br />
For 2008-01-02 = sum of (values 2007-02-01 to 2008-02-01) div by 13<br />
<br />
Better will be <br />
sum ( for month 2007-01-01 to 2008-01-01) (value div by number of day in month)/13<br />
<br />
(10/31)<br />
+(9/31)<br />
+(10/30)<br />
+(13/31)<br />
+(11/30)<br />
+(12/31)<br />
+(18/31)<br />
+(13/30)<br />
+(17/31)<br />
+(12/30)<br />
+(5/31)<br />
+(11/28)<br />
+(10/31)<br />
/ 13
mwilliams
F.P.,
So, you want the moving average for up to 13 months?
fporcher
<blockquote class='ipsBlockquote' data-author="mwilliams"><p>F.P.,<br />
<br />
So, you want the moving average for up to 13 months?</p></blockquote>
Yes, and how to generalyze to N month ...
mwilliams
F.P.,
If you just put '13' in the expression box, it'll show the running average of the last 13 values or how many are before the current one up to 13.
If you could set it up to do "N months", how would you determine N?
fporcher
<blockquote class='ipsBlockquote' data-author="mwilliams"><p>F.P.,<br />
<br />
If you just put '13' in the expression box, it'll show the running average of the last 13 values or how many are before the current one up to 13.</p></blockquote>
<br />
neither one nor the other. It displays the current month<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="mwilliams"><p>If you could set it up to do "N months", how would you determine N?</p></blockquote>
N is fixed in the chart (this is not a variable).<br />
See attachment base on sampleDatabase
fporcher
I create a table with agreagation, in this case, it work
but not in chart
mwilliams
F.P.,<br />
<br />
If you just have one series, it works. If you create a computed column in your dataSet that repeats the value of row["SOMME"] and do the aggregation on the first series using the new computed value for the second series, it works. But if you do the aggregation on the second series in any case, it seems to just follow the first series. This definitely looks like a bug to me. Please log it at <a class='bbc_url' href='
http://www.eclipse.org/birt/phoenix/reportabug.php'>BIRT
: Reporting Bugs and Requesting Enhancements</a>. Be sure to include a good description, screenshots, and the sample report design you posted on here. Please include any bug info in here for future reference. Thanks.<br />
<br />
In the following screenshot, you can see that if you use a computed column called SOMME2, and use it as the second series with the aggregations, the preview shows it correctly. However, when I run it, it is not correct.
turissa
<p>Hello, I have a similar problem and the solution here works for me on a table, but I need a 13 period moving average on a crosstab and the aggregate function MOVINGAVE is not possible. I have two years of values with 13 periods each (network rail periods). I need a script to give me a moving average for each year.<br>
</p>
<p>I have found a javascript expression which gives me a result but it's not quite right. The crosstab is grouped by Year and Period</p>
<p>
</p>
<p>movAveArray.push(data["IMO_MTIN"]);</p>
<p> </p>
<p><b>var</b> movingSum = 0;</p>
<p> </p>
<p><b>for</b> ( <b>var</b> i=movAveArray.length-1; i>=0; --i ) {</p>
<p>movingSum = movingSum + movAveArray
;</p>
<p>}</p>
<p> </p>
<p>movingSum / movAveArray.length;</p>
<p>
I also have the following in the beforeFactory script:</p>
<p>movAveArray = new Array();</p>
<p>
</p>
<p> </p>
<p>This is the sample data and column 3 (Excel) holds the correct result I am looking for:</p>
<p> </p>
<strong><span style="font-size:small;">Period</span></strong>
<strong><span style="font-size:small;">MTIN Miles</span></strong>
<strong><span style="font-size:small;">Excel Moving Average 13</span></strong>
<span style="font-size:small;">1</span>
<div>
<div>
<div><span style="font-size:small;">2,548,011.70</span></div>
</div>
</div>
<span style="font-size:small;">#N/A</span>
<span style="font-size:small;">2</span>
<span style="font-size:small;">10,135,680.00</span>
<span style="font-size:small;">#N/A</span>
<span style="font-size:small;">3</span>
<span style="font-size:small;">7,597,118.30</span>
<span style="font-size:small;">#N/A</span>
<span style="font-size:small;">4</span>
<span style="font-size:small;">3,101,974.00</span>
<span style="font-size:small;">#N/A</span>
<span style="font-size:small;">5</span>
<span style="font-size:small;">55,700.00</span>
<span style="font-size:small;">#N/A</span>
<span style="font-size:small;">6</span>
<span style="font-size:small;">5,039,990.00</span>
<span style="font-size:small;">#N/A</span>
<span style="font-size:small;">7</span>
<span style="font-size:small;">100</span>
<span style="font-size:small;">#N/A</span>
<span style="font-size:small;">8</span>
<span style="font-size:small;">233.3</span>
<span style="font-size:small;">#N/A</span>
<span style="font-size:small;">9</span>
<span style="font-size:small;">174,430.00</span>
<span style="font-size:small;">#N/A</span>
<span style="font-size:small;">10</span>
<span style="font-size:small;">5,710.00</span>
<span style="font-size:small;">#N/A</span>
<span style="font-size:small;">11</span>
<span style="font-size:small;">412</span>
<span style="font-size:small;">#N/A</span>
<span style="font-size:small;">12</span>
<span style="font-size:small;">5,039,990.00</span>
<span style="font-size:small;">#N/A</span>
<span style="font-size:small;">13</span>
<span style="font-size:small;">100</span>
<span style="font-size:small;"><span style="color:rgb(255,0,0);">2,592,265.33</span></span>
<span style="font-size:small;">1</span>
<div>
<div>
<div><span style="font-size:small;">172,855.00</span></div>
</div>
</div>
<span style="font-size:small;">2,409,560.97</span>
<span style="font-size:small;">2</span>
<span style="font-size:small;">55,800.00</span>
<span style="font-size:small;">1,634,185.58</span>
<span style="font-size:small;">3</span>
<span style="font-size:small;">6,044.00</span>
<span style="font-size:small;">1,050,256.79</span>
<span style="font-size:small;">4</span>
<span style="font-size:small;">55,800.00</span>
<span style="font-size:small;">815,935.72</span>
<span style="font-size:small;">5</span>
<span style="font-size:small;">340,000.00</span>
<span style="font-size:small;">837,804.95</span>
<span style="font-size:small;">6</span>
<span style="font-size:small;">500</span>
<span style="font-size:small;">450,151.87</span>
<span style="font-size:small;">7</span>
<span style="font-size:small;">1,684,990.70</span>
<span style="font-size:small;">579,758.85</span>
<span style="font-size:small;">8</span>
<span style="font-size:small;">5,425,721.00</span>
<span style="font-size:small;">997,104.05</span>
<span style="font-size:small;">9</span>
<span style="font-size:small;">1,309,912.00</span>
<span style="font-size:small;">1,084,448.82</span>
<span style="font-size:small;">10</span>
<span style="font-size:small;">85,175.00</span>
<span style="font-size:small;">1,090,561.52</span>
<span style="font-size:small;">11</span>
<span style="font-size:small;">2,905.00</span>
<span style="font-size:small;">1,090,753.28</span>
<span style="font-size:small;">12</span>
<span style="font-size:small;">412</span>
<span style="font-size:small;">703,093.44</span>
<span style="font-size:small;">13</span>
<span style="font-size:small;">113,637.30</span>
<span style="font-size:small;">711,827.08</span>
newbie321
<p>IMHO, If you are doing SMA(x), where x is the time period, then it will be just a matter of time before someone asks you to do EMA or rolling volatility over arbitrary time period as well as run-ups, draw-down, etc etc... When I was doing these things few years ago, I found that creating a custom aggregator gave the most power as well as flexibility. At that time Jason Weathersby (miss him very much although the expert level of current BIRT moderators/evangelists is top notch here) helped me a lot in understanding how to do it. </p>
<p> </p>
<p>I believe if you look through older eclipse/birt forums then you will be able to find a number of references. If my memory does not betray me, I ended up doing an extension to birt, so when you load up birt, these custom aggregations come naturally via the Birt's front end. </p>
<p> </p>
<p>I realize my answer does not solve your problem explicitly but at least it gives you a general direction of the vector of the solution that you might want to explore.</p>
<p> </p>
<p>Hope it helps,</p>