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

Allocated memory exceeded

I am trying to take an average based on a variable field. When I do that I am getting an error Allocated Memory Exceeded.

The Expression is

(SUM($(vPremiumYTD))) / Sum(TOTAL $(vPremiumYTD))*100

The variable $(vPremiumYTD) is

if(GetFieldSelections(PREMIUM_FLAG) = 'AP' or GetSelectedCount(PREMIUM_FLAG)<>1

, (sum(if(T_APPR_DT <= AddYears(max(total T_APPR_DT), T_YEAR - Year(max(total T_APPR_DT))), T_NETPREM)))/vNumber

, if(GetFieldSelections(PREMIUM_FLAG) = 'ER' and GetSelectedCount(PREMIUM_FLAG)=1 ,

   (sum(if(T_APPR_DT <= AddYears(max(total T_APPR_DT), T_YEAR - Year(max(total T_APPR_DT))), T_ER_PREM)))/vNumber

))

1 Reply
d_pranskus
Partner - Creator III
Partner - Creator III

Hi

Using IF function inside the Aggregation function (like SUM) is a bad practice. You need to refactor your expression to use set analysis instead.

It should look something like this:

IF(ONLY(PREMIUM_FLAG) = 'AP,

     SUM({<T_YEAR = {$(=MAX(T_YEAR))}, T_APPR_DT = {"<=$(=DATE(MAX(T_APPR_DT)))"}>} T_NETPREM),

IF(ONLY(PREMIUM_FLAG = 'ER',

     SUM({<T_YEAR = {$(=MAX(T_YEAR))}, T_APPR_DT = {"<=$(=DATE(MAX(T_APPR_DT)))"}>} T_ER_PREM)

))

Basically I am filtering in set analysis on the cuirrtent year and then filtering on the date to be less than max date.