Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
asifshah
Partner - Contributor
Partner - Contributor

How to use RangeAvg in back-end script

I want to generate average values for the past 6 months

example table :

LOAD * INLINE [
Zone, Month, Value
East, Jan-2019, 98823
East, Feb-2019, 98372
East, Mar-2019, 47732
East, Apr-2019, 92838
East, May-2019, 92939
East, Jun-2019, 8822
East, July-2019, 991
East, Aug-2019, 13124
East, Sep-2019, 2324
East, Oct-2019, 231
East, Nov-2019, 1234
East, Dec-2019, 32442
];

 

Using the below function, it gives proper values,

RangeAvg(above(total sum(Value),0,5))

Output:

ZoneMonthValueRangeAvg of Value
EastApr-20199283892838
EastAug-20191312452981
EastDec-20193244246134.66667
EastFeb-20199837259194
EastJan-20199882367119.8
EastJuly-201999148750.4
EastJun-2019882247890
EastMar-20194773250948
EastMay-20199293949861.4
EastNov-2019123430343.6
EastOct-201923130191.6
EastSep-2019232428892

 

However the same function doesn't work in back-end script.

Can anyone help me replicate this scenario in back-end?

Thanks.

 

Labels (4)
2 Replies
marcus_sommer

Above() is an UI function and doesn't work within the script. With previous() and peek() there are interrecord-functions which could be used in the script - but they could pick only a single value and not a range of values. This means you need to add multiple ones - this may (with the help of an additionally variable) look like:

set eP = "peek('Value', $1)";

table:
load *, rangeavg(Value, $(eP(-1)), $(eP(-2)), $(eP(-3)), $(eP(-4))) as AVG
resident Source order by Month;

Important is that you sort the (resident) load appropriate and if there are multiple Zone's or other relevant fields available you need some if-logic to include to consider them (the more circumstances needs to be catched the more benefit has the above created variable to keep the statement small and clear).

- Marcus

Brett_Bleess
Former Employee
Former Employee

Did Marcus' post help you with your use case?  If so, please do not forget to return to your thread and on his post, use the Accept as Solution button to mark it as the solution which will also give him credit for the assistance and let other Members know it did help too.  If you are still working upon things, please leave an update and if you figured out an alternate solution, please consider posting and marking that as the solution.

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.