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: 
sgrobben
Contributor II
Contributor II

Empty values while using [Avg] in combination with [Aggr]

I have a table with, for example, the following data:

Research Agenda StartDate AdmissionDays
Echo FBE117-03-202112
Echo FBE117-07-202125
Echo AbdoE118-05-20210
Echo AbdoE125-06-202125
Echo NeckE113-06-202125
Echo MammoE118-07-20210
Echo MSKE122-07-202171
ArthroDL123-06-202136
OesoDL123-07-202128

 

I only want to count the records where the startdate is the same as the maximum date of that [Research].
I therefore use the following set-expression:

 

if(Min({1}{<[StartDate] = {"$(=Date(Max([StartDate]), 'DD-MM-YYYY'))"}>}[AdmissionDays])=-1,0,
Min({1}{<[StartDate] = {"$(=Date(Max([StartDate]), 'DD-MM-YYYY'))"}>}[AdmissionDays]))

 

Which gives me the following outcome:

Research Agenda StartDate AdmissionDays
Echo FBE117-07-202125
Echo AbdoE125-06-202125
Echo NeckE113-06-202125
Echo MammoE118-07-20210
Echo MSKE122-07-202171
ArthroDL123-06-202136
OesoDL123-07-202128

 

When i want to get the average number per [Agenda] i do the following set-expression:

 

Avg(Aggr(if(Min({1}{<[StartDate] = {"$(=Date(Max([StartDate]), 'DD-MM-YYYY'))"}>}[AdmissionDays])=-1,0,
Min({1}{<[StartDate] = {"$(=Date(Max([StartDate]), 'DD-MM-YYYY'))"}>}[AdmissionDays])),[Research]))

 

I put these values in a seperate table like this:

Agenda Average
E1-
DL132

 

It shows the correct average for agenda [DL1], but gives me an empty answer for agenda [E1]. If I however select only agenda [E1] and submit, it all of a sudden gives me the right answer, like this:

Agenda Average
E129

 

How is it possible that when it shows me all agenda's, one of the agenda's is not shown correctly, while when I select it, it gives me the right calculation?

1 Solution

Accepted Solutions
dwforest
Specialist II
Specialist II

Think you should add [Agenda] to the agrr

Avg(Aggr(if(Min({1}{<[StartDate] = {"$(=Date(Max([StartDate]), 'DD-MM-YYYY'))"}>}[AdmissionDays])=-1,0,
Min({1}{<[StartDate] = {"$(=Date(Max([StartDate]), 'DD-MM-YYYY'))"}>}[AdmissionDays])),[Research],[Agenda]))

View solution in original post

3 Replies
dwforest
Specialist II
Specialist II

Think you should add [Agenda] to the agrr

Avg(Aggr(if(Min({1}{<[StartDate] = {"$(=Date(Max([StartDate]), 'DD-MM-YYYY'))"}>}[AdmissionDays])=-1,0,
Min({1}{<[StartDate] = {"$(=Date(Max([StartDate]), 'DD-MM-YYYY'))"}>}[AdmissionDays])),[Research],[Agenda]))
NageshSG
Partner - Contributor III
Partner - Contributor III

Please try the following, seems to work for me.

Dimension: Agenda

Measure: avg({<StartDate={$(=chr(39)&concat(aggr( max(StartDate),Research),chr(39)&chr(44)&chr(39))&chr(39))}>}AdmissionDays)

If you want to use a Pivot table with Agenda and Research as dimensions:

Measure:  avg({<StartDate={$(=chr(39)&concat(aggr( max(StartDate),Research),chr(39)&chr(44)&chr(39))&chr(39))}>} TOTAL<Agenda> AdmissionDays)

NageshSG
Partner - Contributor III
Partner - Contributor III

Hi @dwforest , I tried this solution but unable to get expected results! Not sure where I am making a mistake.  Please see the attached qvw file.

The idea of proposing the alternate solution is when we use "If" conditions in expressions against a very large data set, it could impact the memory usage.

Thanks for your time.