Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Problem with using "getcurrentfield" function with "Aggr"

Hi Everyone,

I have the requirement to show the top 5 selection results based on cycle group selection. So i tried to use the getcurrentfield function in aggr funtion.But its not working as expected. I used below expression. If i replace getcurrentfield function with field name its working fine. Could some one help me how to fix this. Please see the attached QVW file to be clear.

Below expression is with getcurrentfield function:

=if(aggr(rank(sum(Qty)),getcurrentfield(New))<5,getcurrentfield(New))

Below expression with field name instead of getcurrentfield function.this is working fine.

=if(aggr(rank(sum(Qty)),ID)<5,ID,'others')

Thanks for your help in advance

1 Solution

Accepted Solutions
johnw
Champion III
Champion III

Chris's approach is still good. Just replace the 5 with $(v_top). It does require locking the sort order, though, or you'll get the bottom five instead, for instance.

This is ugly, but as an alternative that doesn't require locking the sort order, you could create a different cyclic group. Add expressions instead of fields, one for each field. So in your example, put these expressions in a cyclic group:

=if(aggr(rank(sum(Qty)),ID)<=$(v_top),ID,'other')
=if(aggr(rank(sum(Qty)),Month)<=$(v_top),Month,'other')

Label them as desired, then use that group instead. Seems to work.

View solution in original post

8 Replies
chris_johnson
Creator III
Creator III

Hi,

I've had a quick look and put together a top 5 list based on your dimension cycle group. I don't think you need to use the aggr function as the totals will be aggregated over the relevant dimension to start with.

If I have understood your question correctly I think most of what you need can be done using the properties in the straight table.

Have a look and see what you think

Regards,

Chris

johnw
Champion III
Champion III

Just use New instead of getcurrentfield(New). You can use a cyclic field just like any other field. You only need to fiddle with getcurrentfield() when you want a TEXT description of which field is current.

Not applicable
Author

Thank you very much for the reply. Smile

Chris, The top 5 is not fixed number. Based on the user input number will change. So i used Aggr function.

John, I try to use the just cycle group name "New" without getcurrentfield function. its working fine but its not giving the option to select the other cycle dimentions. Its showing chart for only one fixed dimention. Please see the attached QVW.

johnw
Champion III
Champion III

Chris's approach is still good. Just replace the 5 with $(v_top). It does require locking the sort order, though, or you'll get the bottom five instead, for instance.

This is ugly, but as an alternative that doesn't require locking the sort order, you could create a different cyclic group. Add expressions instead of fields, one for each field. So in your example, put these expressions in a cyclic group:

=if(aggr(rank(sum(Qty)),ID)<=$(v_top),ID,'other')
=if(aggr(rank(sum(Qty)),Month)<=$(v_top),Month,'other')

Label them as desired, then use that group instead. Seems to work.

Not applicable
Author

With straight table approach i cant show the others total. Above solution worked fine. I appriciate your help. Thankyou verymuch.

johnw
Champion III
Champion III

Do you mean there wasn't a number on the "others" line? I noticed that when I first tried it. It looks like the answer is to set the total mode to the sum of rows instead of expression total.

Not applicable
Author

Yes john, I was not able to see any number on others line. As you suggested, once i changed the totals mode to sum of rows,its working fine. Thanks for your help.

nathanfurby
Specialist
Specialist

For future reference - Use dollar sign to get the string value of the currentfield:

=if(aggr(rank(sum(Qty)),$(=getcurrentfield(New)))<5,$(=getcurrentfield(New)),'Others')