Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Average in Script when

I have the below expression but want to add this into the script. How would one write this? I also would like to remove zero values from the average.

Chart Properties Expression below:

Dimensions: Program

Avg({<ENROLLMENT_STATUS = {'Closed'},REASON ={'a','b'}>}DAYS)

1 Solution

Accepted Solutions
sunny_talwar

May be like this:

LOAD Program,

     Avg(DAYS) as AverageDays

RESIDENT YourTableWithAllFields

WHERE DAYS <>0 AND ENROLLMENT_STATUS = 'Closed' AND MATCH(REASON, 'a','b')

Group By Program;

UPDATE: Used Stefan's code and added the Program as the dimension

View solution in original post

10 Replies
Clever_Anjos
Employee
Employee

Do you need a level of aggregation?

sunny_talwar

Put another way, where did you use this in the front end? A chart or text box object? If it was in chart, what were the dimensions?

swuehl
MVP
MVP

Guessing from the sparse information provided, something like

LOAD

     AVG(DAYS) AS AverageDays

RESIDENT YourTableWithAllFields

WHERE DAYS <>0 AND ENROLLMENT_STATUS = 'Closed' AND MATCH(REASON, 'a','b');

Anonymous
Not applicable
Author

I see. I have updated my question. This was in the Chart Properties and my dimesion field is "Program". I would like the avg to calcuate based off my selections from the list box, but need to only avg when. Enrollment status = 'Closed', Reasons = 'a','b' and Days <> 0

sunny_talwar

May be like this:

LOAD Program,

     Avg(DAYS) as AverageDays

RESIDENT YourTableWithAllFields

WHERE DAYS <>0 AND ENROLLMENT_STATUS = 'Closed' AND MATCH(REASON, 'a','b')

Group By Program;

UPDATE: Used Stefan's code and added the Program as the dimension

Clever_Anjos
Employee
Employee

Why don´t just this into your graph?

Avg({<ENROLLMENT_STATUS = {'Closed'},REASON ={'a','b'},DAYS=[">0"}>}DAYS)

Anonymous
Not applicable
Author

I could and it's nice to now know the syntax. Are there advantages and disadvantages in doing this?

Anonymous
Not applicable
Author

Thanks, I'm almost there. I have in my where clause the string don't. I believe the apostrophe is throwing an error. Is there a way for QV to except the apostrophe. I tried to use Double quotes, but that's not working!

swuehl
MVP
MVP

Try to use two single quotes within the string literal (and enclose with single quotes around).