Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
nafi_qlikview
Partner - Contributor II
Partner - Contributor II

Listbox with Aggr() and additional expressions not working as expected

Hi,

I believe this issue has been discussed in one form or another before, but I couldn't find a solution to my particular problem. I've also read up on how Qlikview deals with NULLs/missing values, but can't see why this would be causing what I'm seeing.

Instead of a straight dimension, I'm using an Aggr() expression as dimension in a listbox to be able to filter down the shown dimension values. In addtion, I show other information for each of the resulting dimension values via the expression tab.

Problem is, that the expressions displayed and the sort order applied isn't what it should be.

Here's an example (Since I couldn't manage to include screenshots inline, I'll enter the values in tables):

Input data:

LOAD *

INLINE [

  ID, Name

  1 , 'Test1'

  2 , 'Test2'

  3 , 'Test3'

  4 , 'Test4'

];

LOAD *

INLINE [

  ID, Filter, Value

  1 , 1     , 1

  2 , 1     , 1

  1 , 2     , 1

  3 , 2     , 1

];

The dimension in the first listbox is 'Aggr(Only(Name), Name)' (the Only() will contain filters in the real app, but they aren't needed for demonstration of the issue; in fact even 'Aggr(Name, Name)' behaves the same way). For demonstration puposes, I've also created a second listbox with the straight dimension 'Name', which behaves as expected. Both are ordered by the first expression column, descending.

Aggr(Only(Name), Name)Sum({<Filter={1}>} Value)Sum({<Filter={2}>} Value)Sum(Value)
Test4000
Test3011
Test2101
Test1112
NameSum({<Filter={1}>} Value)Sum({<Filter={2}>} Value)Sum(Value)
Test1112
Test2101
Test3011
Test4000

As you can see, the sort order is already off in here. If I now also disable the last expression, I get the following:

Aggr(Only(Name), Name)Sum({<Filter={1}>} Value)Sum({<Filter={2}>} Value)
Test4
Test301
Test210
Test111
NameSum({<Filter={1}>} Value)Sum({<Filter={2}>} Value)
Test111
Test210
Test301
Test400

Now the line for Test4 is completely empty in the first listbox, but it's still shown. Note: It's not displaying '-' to indicate that it's NULL.

Can anyone please explain why Aggr() messes the whole thing up?

Thanks,

Martin

1 Solution

Accepted Solutions
stigchel
Partner - Master
Partner - Master

My guess is that this is because calculated dimensions are evaluated differently. See e.g.

https://community.qlik.com/blogs/qlikviewdesignblog/2013/08/06/it-s-all-aggregations

If you use the same aggregation in your expressions,

Aggr(Sum({<Filter={1}>} Value),Name)

The results and sorting will be what you expect. Should you want to display 0 instead of missing you can wrap it in a sum expression, so

Sum(Aggr(Sum({<Filter={1}>} Value),Name))

View solution in original post

2 Replies
stigchel
Partner - Master
Partner - Master

My guess is that this is because calculated dimensions are evaluated differently. See e.g.

https://community.qlik.com/blogs/qlikviewdesignblog/2013/08/06/it-s-all-aggregations

If you use the same aggregation in your expressions,

Aggr(Sum({<Filter={1}>} Value),Name)

The results and sorting will be what you expect. Should you want to display 0 instead of missing you can wrap it in a sum expression, so

Sum(Aggr(Sum({<Filter={1}>} Value),Name))

nafi_qlikview
Partner - Contributor II
Partner - Contributor II
Author

Awesome, it works! And the Sum() tip is very useful.

Thanks you so much, I've already spent quite a while looking into this!