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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
akash_durai1507
Contributor II
Contributor II

Help Optimizing an expression with AGGR

Sum(Aggr(max( {<GLaccountCode={'121001','117000'}>}If((YearEndDate>=NetDueDate and [Clearing Date]>YearEndDate and Arrears>0) or AROverdue='Overdue',ARAmountLC)
),YearFilter,ARKey))

Above is my expression i use on charts and its very slow when there are no filters.

I'm using an As-of table and when i apply filters inside the if-clause, the amount is duplicated(guessing its due to many-to-many joins) and I'm forced to use Max() inside the AGGR() function.

My data model looks like below,

akash_durai1507_0-1765828964363.png


TIA,

4 Replies
rwunderlich
MVP
MVP

When you built the link table, did you apply the DISTINCT operator?

-Rob

akash_durai1507
Contributor II
Contributor II
Author

Hi Rob!

Thanks for the reply.

Yes, i did apply distinct operator while loading the link table.

Here is the snapshop of the code,

akash_durai1507_1-1765879974119.png

 

 

Chanty4u
MVP
MVP

Try this in your load script 

AR_Snapshot:

LOAD

    YearEndDate,

    ARKey,

    Max(

        If(

            (YearEndDate>=NetDueDate 

             and [Clearing Date]>YearEndDate 

             and Arrears>0)

            or AROverdue='Overdue',

            ARAmountLC

        )

    ) as ARAmount_AsOf

Resident AsOfTable

Group By YearEndDate, ARKey;

marcus_sommer
MVP
MVP

I suggest to make the date-checks already within the data-model an refer then within the expressions to these flags, for example with an approach like:

sign(date1 - date2) as flagX

This may need some measurements to bring the various dates together and should be used to consider to rebuild the data-model because link-table approaches may end in a working data-model but from a performance point of view are they usually not the best choice.