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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Average values by distinct date

Here is an example of my data set.

datecasestype
4/26/2014
4/25/2014092
4/25/2014193
4/25/20141162
4/24/2014192
4/24/2014393
4/23/2014092
4/23/2014093
4/22/2014092
4/22/2014093
4/22/20140162
4/21/2014092
4/21/2014093
4/21/2014097
4/21/20140162
4/20/2014 92
4/20/2014 93
4/20/2014 97
4/20/2014 162

I would like to average the "cases" per day, regardless of "type".  So, this would be an average of 1.2 (=6/5), since there were 2 on 4/24/2014, 4 on 4/24/2014, and 0 on 4/23/2014, 4/22/2014, and 4/21/2014.  My average would not include 4/20/2014 or 4/26/2014 since the value for "cases" has a null on those days.

I tried avg(cases), but that gives me 0.375 (=6/16).  It's counting all the numbers in the "cases" column as an instance.

I tried avg({<cases = {'<>0'}>} cases), but that gives me 1.5 (=6/4).  It's counting all the non-zero numbers in the "cases" column as an instance, but I want it to count just the ones with distinct dates.

I tried avg(distinct {<cases = {'<>0'}>} cases), but that gives me 1.5 (=2/2).  It's only taking '3' and '1' as the two instances to average.

I tried aggr, but I can't get that to even give me a number.  I think I'm using it wrong.

Any ideas?

1 Solution

Accepted Solutions
swuehl
MVP
MVP

What about

=sum(cases) / count({<cases = {"*"}>} distinct date)

View solution in original post

3 Replies
Not applicable
Author

In case it matters, I want to aggregate this number to use it in a text box, not a chart or anything like that.

swuehl
MVP
MVP

What about

=sum(cases) / count({<cases = {"*"}>} distinct date)

Not applicable
Author

That worked, thanks!