Hi,

I would like to ask if its possible to have a moving average

formula in a datawindow? Please give code snippet.

TIA,

Neil

like CumulativeSum()/rownum() expression

It should be getrow() instead of rownum()

I'm sorry to much Oracle/PB switching just before weekend starts

I think what I need is a little different from this

formula...

Example:

In a datawindow, I have a number column col1 with 100 rows

and I want a computed column like a moving average with the

LENGTH of 10.

This computed field will start to have a value at row 10,

which it sum-up col1 from row 1 to row 10 divide by 10...

At row 11, it will summ-up row 2 to row 11, divide by 10.

At row 12, it will summ-up row 3 to row 12, divide by 10.

At row 13, it will summ-up row 4 to row 13, divide by 10.

At 100th row, it summ-up from row 91 to row 100 divide by

10.

This is what I mean as "moving"... the row keeps moving.

First of all which DB are you using ?

Oracle for example can deliver this with analytical functions.

DW can access data in different rows... use col[-1] to access value from

previous row.

this would make your formula like :

If ( getrow()> 9,

(col[-9]+col[-8]+col[-7]+col[-6]+col[-5]+col[-4]+col[-3]+col[-2]+col[-1]))/10,0)

BTW you should let us know which version of PB you're using

use then Arthur's solution. create a computed containing amount of rows

you want to process (for this example you can name it cf_rows

an then

sum( if( currentrow - getrow() < cf_rows and currentrow - getrow() >= 0,

ValueToSum, 0 )) / cf_rows?

not tested but worth a trying

You can easily modify value of cf_rows with simple modify.