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

Getting an Average in Set Analysis

Hello:

I am trying to find the average of days, and I know I need more on my Set Analysis, but noting I do is returning the correct value.  I have dropped the set analysis back down to the bare minimum for this post.  I need to find the average of [Issue Age], and need to keep the Distinct on the Issue ID and also maintain the Load Date portion of the set analysis as well.

Is it possible?

=Num(Avg(DISTINCT{<[Issue Age]={'>0'},[Load Date] = {'$(=Max([Load Date]))'}>} [Issue ID])/[Issue Age],'##,###')

Thank you in advance for your help

1 Solution

Accepted Solutions
sunny_talwar

Try this:

=Avg({<[Load Date] = {"$(=Date(Max([Load Date])))"}>}Aggr(Only({<[Load Date] = {"$(=Date(Max([Load Date])))"}>} [Issue Age]), [Issue ID]))

or

=Avg({<[Load Date] = {"$(=Date(Max([Load Date])))"}>}Aggr(Sum(DISTINCT {<[Load Date] = {"$(=Date(Max([Load Date])))"}>} [Issue Age]), [Issue ID]))

or

=Avg({<[Load Date] = {"$(=Date(Max([Load Date])))"}>}Aggr(Max({<[Load Date] = {"$(=Date(Max([Load Date])))"}>} [Issue Age]), [Issue ID]))

or

=Avg({<[Load Date] = {"$(=Date(Max([Load Date])))"}>}Aggr(Min({<[Load Date] = {"$(=Date(Max([Load Date])))"}>} [Issue Age]), [Issue ID]))

or

=Avg({<[Load Date] = {"$(=Date(Max([Load Date])))"}>}Aggr(Avg({<[Load Date] = {"$(=Date(Max([Load Date])))"}>} [Issue Age]), [Issue ID]))

all should provide the same result

View solution in original post

8 Replies
sunny_talwar

Would you be able to share few rows of data with the output you expect to see from the input provided?

Not applicable
Author

  Hi Sunny, I just created some data for this string. This is the type of data I am working with.  

Load DateIssue IDIssue Age
12/29/20161234224
12/29/201622255123
12/29/20161234782
12/29/20164444852
12/29/201655556235
12/29/201688821224
12/29/201666994774
12/29/201666994145
12/29/201678945123
12/29/201644877782
12/29/20164487652
12/29/201644879235
12/29/201655514224
12/15/201622255116
12/15/20161234775
12/15/20164444845
12/15/201655556228
12/15/201688821217
12/15/201666994767
12/15/201666994138
12/15/201678945116
12/15/201644877775
12/15/20164487645
12/15/201644879228
12/15/201655514217
12/15/201622212925
12/15/201623461871
12/15/2016444871112
12/8/201622255109
12/8/20161234768
12/8/20164444838
12/8/201655556221
12/8/201688821210
12/8/201666994760
12/8/201666994131
12/8/201678945109
12/8/201644877768
sunny_talwar

What is the expected output?

Not applicable
Author

I am looking to get an average of issue Age, based on the Load Date.  The Average, needs to be distinct, since there are duplicate Issue IDs.

We use Load date as a main  filter in all of our tables in QV.  We use Max Load Date, but also have a filter to be able to look at previous load dates, which is why the calc has Load Date and Max Load date included.

sunny_talwar

Within your sample we have Issue ID 66994 repeating two times. How would you use this information here? Sum the Issue Age and then find the average Issue Age?

Capture.PNG

For the Load Date = 12/29/2016 (Max Date), I get 361.36364. Is this what you expect to see

Capture.PNG

Expression used

=Avg({<[Load Date] = {"$(=Date(Max([Load Date])))"}>}Aggr(Sum({<[Load Date] = {"$(=Date(Max([Load Date])))"}>} [Issue Age]), [Issue ID]))

Not applicable
Author

Hello Sunny:

I apologize, the dups for the same date should have the same number of days associated with them.

The formula you provided is not working, it is not removing the duplicates. (Which is an issue with the data I provided as a sample, as stated above)

sunny_talwar

Try this:

=Avg({<[Load Date] = {"$(=Date(Max([Load Date])))"}>}Aggr(Only({<[Load Date] = {"$(=Date(Max([Load Date])))"}>} [Issue Age]), [Issue ID]))

or

=Avg({<[Load Date] = {"$(=Date(Max([Load Date])))"}>}Aggr(Sum(DISTINCT {<[Load Date] = {"$(=Date(Max([Load Date])))"}>} [Issue Age]), [Issue ID]))

or

=Avg({<[Load Date] = {"$(=Date(Max([Load Date])))"}>}Aggr(Max({<[Load Date] = {"$(=Date(Max([Load Date])))"}>} [Issue Age]), [Issue ID]))

or

=Avg({<[Load Date] = {"$(=Date(Max([Load Date])))"}>}Aggr(Min({<[Load Date] = {"$(=Date(Max([Load Date])))"}>} [Issue Age]), [Issue ID]))

or

=Avg({<[Load Date] = {"$(=Date(Max([Load Date])))"}>}Aggr(Avg({<[Load Date] = {"$(=Date(Max([Load Date])))"}>} [Issue Age]), [Issue ID]))

all should provide the same result

Not applicable
Author

Thank you so much for all of your help Sunny!