Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
demoustier
Creator
Creator

RangeAvg(Above()) on script

Good day,

Despite several postson this subject, I still not found the solution to my issue below:

I have a table with record of engine power, one line per minute and 1 year of records => huge amount of lines
I need to calculate for each record the average power of the 6O previous lines.

 

On a graph, I can use RangeAvg(Above([Power],0,60) but I need to calculate it on script level.

 

Any idea ???

 

Many thanks and kind regards

2 Solutions

Accepted Solutions
Taoufiq_Zarra

@demoustier  can you share a sample data and the expected output ?

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

sunny_talwar

@demoustier one way you can try

Table:
LOAD signaldate, 
     Value
FROM
[C:\Users\talwars\Downloads\sample (2).xlsx]
(ooxml, embedded labels, table is Feuil1);

tmpTable:
LOAD RowNo() as RowNum,
	 *
Resident Table
Order By signaldate;

tmp2Table:
LOAD 0 as RowNum
AutoGenerate 0;

For i = 0 to 59
	
	Concatenate (tmp2Table)
	LOAD RowNum + $(i) as RowNum,
		 RowNum as OriginalRowNum,
		 Value
	Resident tmpTable;

NEXT

Left Join (tmpTable)
LOAD RowNum,
	 Avg(Value) as Result
Resident tmp2Table
Group By RowNum;

DROP Tables Table, tmp2Table;

View solution in original post

4 Replies
Taoufiq_Zarra

@demoustier  can you share a sample data and the expected output ?

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
demoustier
Creator
Creator
Author

Hi,

attched sample set of data.
Column A and B are data, column C is the expected output.
On each row, I need in column C the average of the last 60 value in column B...

Thank you for your help !

Regards

sunny_talwar

@demoustier one way you can try

Table:
LOAD signaldate, 
     Value
FROM
[C:\Users\talwars\Downloads\sample (2).xlsx]
(ooxml, embedded labels, table is Feuil1);

tmpTable:
LOAD RowNo() as RowNum,
	 *
Resident Table
Order By signaldate;

tmp2Table:
LOAD 0 as RowNum
AutoGenerate 0;

For i = 0 to 59
	
	Concatenate (tmp2Table)
	LOAD RowNum + $(i) as RowNum,
		 RowNum as OriginalRowNum,
		 Value
	Resident tmpTable;

NEXT

Left Join (tmpTable)
LOAD RowNum,
	 Avg(Value) as Result
Resident tmp2Table
Group By RowNum;

DROP Tables Table, tmp2Table;
demoustier
Creator
Creator
Author

Wow !!! Great !!!

it works perfectly with one set of data (one Entity) ! many thanks

 

Now I have to manage with several Entity

Many thanks !!!!!