Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Sum doesn't "roll up" when collapsed

I have a table with 3 dimensions and two expressions. With the dimensions completely expanded, I get the values I'm looking for in "New business" and "Core business", but when they are collapsed, the sum of the Core and New business values don't roll up correctly. New Business gets rolled into Core:

Capture.PNG

Capture1.PNG

Capture2.PNG

Here are my two expressions:

Core Business:

     Sum({$*BM08 <[Fiscal Year]={'$(FiscalCurrentYear)'},[Customer Sub Type]-={'ENT-Human'}>}[Sales Amount]) - Column(2)

New Business:

     if (Sum({$*BM08 <[Fiscal Year]={'>=$(=FiscalCurrentYear-2)<$(FiscalCurrentYear)'},[Customer Sub Type]-={'ENT-Human'}>}[Sales Amount]) <= 0,

               Sum({$*BM08 <[Fiscal Year]={'$(FiscalCurrentYear)'},[Customer Sub Type]-={'ENT-Human'}>}[Sales Amount]),0)

Can someone explain why this is happening and suggest how to fix it? Thanks in advance.

1 Solution

Accepted Solutions
calvindk
Creator III
Creator III

I think it should work like you want (although probably a bit slow) if you nest the if inside the aggr

Something like this:

Sum(aggr(

If(Sum({$*BM08 <[Fiscal Year]={'>=$(=FiscalCurrentYear-2)<$(FiscalCurrentYear)'},Month={'*'},[Customer Sub Type]-={'ENT-Human'}>}[Sales Amount])<=0,

Sum({$*BM08 <[Fiscal Year]={'$(FiscalCurrentYear)'},[Customer Sub Type]-={'ENT-Human'}>}[Sales Amount]),[Sales Catalog Sub Section],[Ship To])),0)

i might be slightly off with syntax, but give it a try.

View solution in original post

8 Replies
Anonymous
Not applicable
Author

Why this is happening: I think that the "New Business" expression returns 0 in the collapsed mode because the condition returns false for the overall territory.
How to fix: If my assumption above is correct, you need not just a sum, but sum of sums grouped by dimensions, e.g.:
sum(aggr(expression, "Sub Section", "Ship To"))

The "Core Business" expressions probably will be correct after fixing the "New Business".

Regards,
Michael

Not applicable
Author

Thank you so much for your reply Michael and PLEASE stick with me to get this figured out; I will be forever in your debt

Is this what you propose:

if (sum(aggr(Sum({$*BM08 <[Fiscal Year]={'>=$(=FiscalCurrentYear-2)<$(FiscalCurrentYear)'},[Customer Sub Type]-={'ENT-Human'}>}[Sales Amount]) <= 0,[Sub Section],[Ship To])),

          sum(aggr(Sum({$*BM08 <[Fiscal Year]={'$(FiscalCurrentYear)'},[Customer Sub Type]-={'ENT-Human'}>}[Sales Amount]),[Sub Section],[Ship To])),0)

I have tried it, but the results weren't correct and there was an immense amount of processing.

Not applicable
Author

I was able to get my expression working correctly. Unfortunately, when I collapse the dimensions, it still does not roll up. I've determined that this is caused by the IF statement. If I remove the IF and use only the expression, the values roll up (although incorrect). Is there a way to write the same expression without using the IF statement? Like with an e() in set analysis? Here is the expression:

If(Sum(aggr(Sum({$*BM08 <[Fiscal Year]={'>=$(=FiscalCurrentYear-2)<$(FiscalCurrentYear)'},Month={'*'},[Customer Sub Type]-={'ENT-Human'}>}[Sales Amount]),[Sales Catalog Sub Section],[Ship To]))<=0,

Sum(aggr(Sum({$*BM08 <[Fiscal Year]={'$(FiscalCurrentYear)'},[Customer Sub Type]-={'ENT-Human'}>}[Sales Amount]),[Sales Catalog Sub Section],[Ship To])),0)

calvindk
Creator III
Creator III

I think it should work like you want (although probably a bit slow) if you nest the if inside the aggr

Something like this:

Sum(aggr(

If(Sum({$*BM08 <[Fiscal Year]={'>=$(=FiscalCurrentYear-2)<$(FiscalCurrentYear)'},Month={'*'},[Customer Sub Type]-={'ENT-Human'}>}[Sales Amount])<=0,

Sum({$*BM08 <[Fiscal Year]={'$(FiscalCurrentYear)'},[Customer Sub Type]-={'ENT-Human'}>}[Sales Amount]),[Sales Catalog Sub Section],[Ship To])),0)

i might be slightly off with syntax, but give it a try.

Not applicable
Author

THANK YOU! THANK YOU! THANK YOU! ANDERS!!! If I had a way to give you more points, I would. The syntax was just slighty off, but with a little bit of tweaking, it solved my problem. FINALLY!

Here is the final version:

Sum(aggr(

If(Sum({1*BM08 <[Fiscal Year]={'>=$(=FiscalCurrentYear-2)<$(FiscalCurrentYear)'},Month={'*'},[Customer Sub Type]-={'ENT-Human'}>}[Sales Amount])<=0,

          Sum({$*BM08 <[Fiscal Year]={'$(FiscalCurrentYear)'},[Customer Sub Type]-={'ENT-Human'}>}[Sales Amount]),0),[Sales Catalog Sub Section],[Ship To]))

Thanks again!

calvindk
Creator III
Creator III

You are most welcome. Glad i could help

Best wishes

Anonymous
Not applicable
Author

venturebrowser wrote:

... If I had a way to give you more points, I would. ...

You have this way now - you can give more points to Andres by marking his last reply as "helpful" 🙂

Regards,

Michael

Not applicable
Author

Good idea. Done!