Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Calculate the Average of a pre defined variable

I have defined a variable which performs a calculation.

I then want a seperate field to calculate the average of the output of the variable,

I tried using Avg($(HISTORY))

but to no avail

1 Solution

Accepted Solutions
Not applicable
Author

hi this has been resolved by Jens Frederik Kristiansen

=interval(avg(aggr((sum(CHKS)-sum(SCH)),[FLT-NO],DATE)),'mm')

Tthanks for everyones assistance

View solution in original post

13 Replies
swuehl
MVP
MVP

Please note that you can't embed an aggregation function like sum() into another like avg() without using advanced aggregation function aggr().

So if you variable expands to something like sum(Value), this will not be a valid expression:

avg(sum(Value))

And if your variable expands to a result, i.e. a number already, there is no need to use avg().

So how have you defined your variable?

Not applicable
Author

1.png

Sorry I am still getting to grips with this.

Is this the correct information you have requested?

swuehl
MVP
MVP

I can't see a variable named HISTORY, so I would assume no.

Not applicable
Author

it is correct sorry I changed DELAYMIN to HISTORY

Not applicable
Author

2.png

swuehl
MVP
MVP

Please check

http://www.qlikfix.com/2011/06/08/not-all-variables-are-created-equal/

for the difference in using an equal sign or not using one in a variable definition.

In which context do you want to use your new expression? In a chart expression? So you may want to try with creating a variable with no equal sign

Minute(frac(Timestamp1)-frac(Timestamp2))

(and please check the type of brackets you are using, I would suggest using always round brackets () with functions like frac() )

Not applicable
Author

Thanks for the link.

I have amended the variable as per your advice.

I want the new expression to use the output result of HISTORY to provide the average. If there is another way I have no idea

Not applicable
Author

Is anyone able to provide any additional assistance?

swuehl
MVP
MVP

It would be much easier to help you if you could post a small sample app. Still too many unknowns for me to understand your issue.