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

How to write expression using nested sum ??

Dear all,

I am writing a expression using nested sum, but result coming null

Please any one guide me that what I doing wrong ASAP.

Expression :

Sum(

       if( [Due Date] > vWorkDate,

            sum(if(trnType='OUTSTND',[Amount To Customer])) +

            sum(pmtRecd)

       )

)

Or

sum(

       if( [Due Date] > vWorkDate, Column(4) )

)

Thanks & Regards

--anil

8 Replies
swuehl
MVP
MVP

You are embedding an aggregation function into another aggregation function (sum into sum), which is not allowed.

You may need to use advanced aggregation using aggr() function.

Then also check that your variable vWorkDate is compatible with [Due Date] in format.

Not applicable
Author

Dear Sir,

Thanks for your reply,

Yes, both dates are in same format.

can you please explain more about aggr() function, I read help but unfortunately I am not able to understand that how

to convert this expression in to aggr() function expression.

Thanks & Regards

--anil

swuehl
MVP
MVP

aggr() is like an inline table in your expression, with its own expression and dimensions. since you are getting back some kind of column like in a real table, you then are allowed to aggregate over this column. The exact syntax is depending on what you want to achieve and what your expression / dimensions are.

In your above expression, what do you want to achieve with your expression? What is the context of this expression (i.e. in what kind of chart object do you use it, with what dimensions?)?

Maybe you could just put your Due Date > vWorkDate condition just inside your inner sum as additional condition, or maybe you could just remove the outer sum? I don't know, since I don't know your requirement and setting.

Not applicable
Author

Dear Sir,

I am attaching my sample data here, I think now it is easy to understand.

Please now explain

thanks & regards

--anil

swuehl
MVP
MVP

In your case, it really could be enough to remove the outer sum() from your expressions, since you already group by due date in your dimensions.

Check attached modifications.

Regards,

Stefan

Not applicable
Author

Dear Sir,

As soon as I convert this table in to Pivot then again chart is without total

and the Total mode options are disabled ?

--anil

swuehl
MVP
MVP

A pivot table will use an expression total for your total line. Here you don't get any results, because your if() will not return One single answer two your condition, so the result is undefined (the total line has all due dates linked, so there is no unambiguous answer to the condition). In the straight table, I used the total mode sum of rows to get the correct total, which is not available in a pivot table for any reason.

You could get a sum of rows also in a pivot table, using advanced aggregation (please look into the Help, sum of rows in pivot tables).

But I noticed that you can also include your if() statements into your sums, then the expression total could still be calculated. Please see attached.

There are several things that one could be optimize:

1) Use set expressions instead of the sum(if() ) statements, set expressions should perform much better.

2) Also I think your calculated dimensions could probably be replaced by set analysis in your expression

But first check that current results seems reasonably.

Not applicable
Author

Dear Sir,

Thanks a lot, It Is Working, I will defiantly workout on your suggestions in future.

Heads off to your Sir, may god give you a happy and healthy life.

Regards

--anil