Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
yonghanfi
Contributor II
Contributor II

Add the new rows with the value of rolling average value

Let's say I have a Currency table which can be simplified like below:

  

daterate currency
….………..
28.12.20177,4455DKK
29.12.20177,4449DKK
30.12.20177,4449DKK
31.12.20177,4449DKK
1.1.20187,4449DKK
2.1.20187,4437DKK
3.1.20187,4442DKK
4.1.20187,4449DKK
5.1.20187,4459DKK
6.1.20187,4459DKK
7.1.20187,4459DKK
8.1.20187,4467DKK

Let's assume the date start from 01.01.2016, I need to extend the data to one year in the future e.g. until 8.1.2019, and set the rate be the rolling average of the history data in last 365 days.

what I did was as below,

table_temp:

LOAD

date,

Currency,

rate ,

FROM sourceData.qvd

where Currency_id = 'DKK'

;

join


LOAD

date(Today()-2 + iterNo())  as date,

'DKK' as currency

AUTOGENERATE 1

While date(Today()-2 + iterNo()) <= AddYears(Today()-2,1);

currency:

NOCONCATENATE

load

     date,

      currency,

      if(IsNull(rate), RangeAvg(rate), rate) as rate,  

      currency_key

Resident table_temp

order by exchange_rate_date;

drop Table table_temp;



but I don't get, why rangeAvg(rate) did not work, instead it only returned the rate value from previous row.

Could anyone give some help? How can I get rate value from the last year's rolling average? Thanks!

5 Replies
Anil_Babu_Samineni

RangeAvg() should covered 2 arguments. Can you try this?

If(IsNull(rate), RangeAvg(rate, 0), rate) as rate, 

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
yonghanfi
Contributor II
Contributor II
Author

I tried RangeAvg(rate, 0), did not work, instead it only assign 0 as rate value after date 9.1.2018. Could you also explain what is the second argument in rangeavg()?

Thanks! Yong

Anil_Babu_Samineni

Try this?

currency:

NOCONCATENATE

load

      date,

      currency,

      if(IsNull(rate), RangeAvg(Sum(rate),0), rate) as rate, 

      currency_key

Resident table_temp Group By date, currency, currency_key

order by exchange_rate_date;

Or else please share QVD/QVW??

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
yonghanfi
Contributor II
Contributor II
Author

Sorry, still not working. After reload, it complain "Invalid expression". My testing results show that whenever I use sum or other aggr function into to the script, it start to complain  "Invalid expression".

Anil_Babu_Samineni

Fine, Can you provide sample application

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful