Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
bjdouglas
Contributor II
Contributor II

Can you use a calculated field as sort criteria in an Aggr() function?

I'm using the Class() and Aggr() function in concert to get 10 equal OLDPREMIUM groups. The sort criteria for the Aggr() function is a calculated field. I'm getting an invalid dimension error. The set analysis criteria is valid based on other calculated measurements I've done. I suspect you can't use a calculated field as sort criteria in an Aggr() function. Code is below. Any assistance you can provide would be appreciated. Thanks.

=class(

aggr({$<ACCT_YR={"$(vMaxCurYr)"}, ACCT_MO={"<=$(vMaxCurMo)"}>}sum(OLDPREMIUM),

If(Sum(RENLDIF)<>0,

Pow(Sum(NEWPREMIUM)/Sum(OLDPREMIUM),Sum(PRICEDIF)/Sum(RENLDIF)),

Exp(Sum(PRICEDIF)/Sum(OLDPREMIUM)))-1),

sum(OLDPREMIUM)/10)

2 Replies
vamsee
Specialist
Specialist

As you are using class function. Have a look at the following where he says use Dual() to sort your data.

You Have No Class: The Coolest Qlik Function You Aren’t Using

bjdouglas
Contributor II
Contributor II
Author

Yes. That's where I got this code. The dual function is used so that the string literal that is coming out of the class() function in that article is sorted properly. I have even gotten that far yet. I'm getting an invalid dimension error in QlikSense.