Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

can not subtotal when use aggr function

Hi all,

Please see below image, Total column calculate 0 (ZERO) against some branches. Which is wrong, it suppose to give me total.

My Expression is below

if(vFromDate >= Sdate1,sum({<T_Date= {'>=$(vFromDate) <=$(vToDate)'} >}Tday),
aggr(sum(if(T_Date>=Sdate1 and T_Date <= vToDate ,Tday)), DECDDT1,Sdate1Branch, [Branch Name],[RSM Name]))

Is anything wrong/modify in expression?

subtotal zero.png

11 Replies
michael_maeuser
Partner Ambassador
Partner Ambassador

I guess you neet to put the whole expression in an additional sum

if(vFromDate >= Sdate1,sum({<T_Date= {'>=$(vFromDate) <=$(vToDate)'} >}Tday),
SUM(aggr(sum(if(T_Date>=Sdate1 and T_Date <= vToDate ,Tday)), DECDDT1,Sdate1Branch, [Branch Name],[RSM Name])))

Not applicable
Author

I have done this but now total is coming up complete wrong.

see below

subtotal zero1.png

michael_maeuser
Partner Ambassador
Partner Ambassador

as far as I see the total column shows the sum of the last three columns. what do you expect as result?

michael_maeuser
Partner Ambassador
Partner Ambassador

ok now I see your problem.

you can try this

f(vFromDate >= Sdate1,sum({<T_Date= {'>=$(vFromDate) <=$(vToDate)'} >}Tday),
SUM(distinct aggr(sum(if(T_Date>=Sdate1 and T_Date <= vToDate ,Tday)), DECDDT1,Sdate1Branch, [Branch Name],[RSM Name])))


or you can do it with dimensionality / secondary dimensionality function

Not applicable
Author

What ever that data by Month is correct but total is wrong for example...

Branch no 180 total should be 46(19+22+5) and so on for other branches.

subtotal zero2.png

michael_maeuser
Partner Ambassador
Partner Ambassador

can you upload sample data?

yevgeniy
Creator
Creator

Hi

Try to add to start the expression sum() :

sum(

if(vFromDate >= Sdate1,sum({<T_Date= {'>=$(vFromDate) <=$(vToDate)'} >}Tday),
aggr(sum(if(T_Date>=Sdate1 and T_Date <= vToDate ,Tday)), DECDDT1,Sdate1Branch, [Branch Name],[RSM Name]))

)

Not applicable
Author

Now working. No data comes up.


Not applicable
Author

I can't provide sample data because its linked with other 10 tables.

I have notice that data is correct by month but total is wrong only when if T_Date>=Sdate1.

Vinay