Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Show Distinct String as Result of 1st Expression

Using the table below I am trying to create a straight table with Primary dimension of Catgory that shows me two calculations.

1. Show the value with the highest Savings - I believe I have figured this out: Max(Aggr(Sum(Savings),[Supplier],Category))

2. Show the distinct Supplier name associated with result of the above calculation.

I cannot figure out the second calculation. I have tried firstsortedvalue, minstring, maxstring with no success. Adding as a secondary dimension does not help either. 

Starting with this data:

CategorySupplierSavings
SafetySupplier 12342
JanitorialSupplier 11231
ToolsSupplier 167
SafetySupplier 2633
JanitorialSupplier 2234
ToolsSupplier 27997
SafetySupplier 37733
JanitorialSupplier 323
ToolsSupplier 357

This is the Result I am looking for:

CategorySupplierSavings
JanitorialSupplier 11231
ToolsSupplier 27997
SafetySupplier 37733

Thanks

1 Solution

Accepted Solutions
Gysbert_Wassenaar

Try FirstSortedValue(Supplier, -aggr(sum(Savings),Supplier,Category))


talk is cheap, supply exceeds demand

View solution in original post

4 Replies
swuehl
MVP
MVP

Create a straight table chart with dimension Category and two expression:

=FirstSortedValue(Savings, -Savings)

=FirstSortedValue(Supplier, -Savings)

Gysbert_Wassenaar

Try FirstSortedValue(Supplier, -aggr(sum(Savings),Supplier,Category))


talk is cheap, supply exceeds demand
Not applicable
Author

Thanks Gysbert, much appreciated. May I ask what the ( - ) symbol in front of the aggr function does?

swuehl
MVP
MVP

The minus sign negates the outcome of the aggr() function. Why do you have to do this?

Please check the HELP for FirstSortedValue():

"...Sort-weight should return a numeric value where the lowest value will render the corresponding value of expression to be sorted first. By preceding the sort-value expression with a minus sign, the function will return the last value instead...."

And you are looking for Supplier with highest savings.

There is no need to use advanced aggregation (aggr() function) in your chart expression if your data table in your data model matches what you posted above, Savings already aggregated by Category and Supplier.