Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Somsok
Contributor
Contributor

FirstSortedValue and Aggr Chart Functions in Straight Table - Dimensions are ignored?

Hi all,

I am trying to create a table displaying the Customer with the most sales for each Product: 

Customer Product Sales
Cust 1 Prod 1 1
Cust 1 Prod 2 11
Cust 2 Prod 1 2
Cust 2 Prod 2 2
Cust 3 Prod 1 3
Cust 3 Prod 2 3
Cust 4 Prod 1 3

 

I found the chart function FirstSortedValue to get the top customer for each product.
However, only the first row is displayed and incorrect. I think the problem is the inner agg() function. I also visualized this part of the function for testing:

Somsok_0-1717593121092.png


In my understanding sum(Aggr(sum(Sales), Customer)) should only include sales of Prod 1 in row 1 and sales of Prod 2 in row 2. Can anybody can help me out with this? Why does row 1 include Prod 1 and Prod 2 numbers even though the Product Dimension value is Prod 1?

 

Tanks for your Help!

Labels (4)
1 Solution

Accepted Solutions
Somsok
Contributor
Contributor
Author

@Or Thank you for the input! 
My Data table is highly simplified. In the real case I will have multiple rows of the same Customer and Product I want to sum up. Your solution works if I want to display the Customer with the highest single order. However, I want to see which Customer has the highest order total.

I found a working solution for me:
FirstSortedValue(distinct Customer, -Aggr(sum(Sales), Customer, Product), 1)
I just had to also include the Product in the Aggr statement.

View solution in original post

2 Replies
Or
MVP
MVP

Dimension: Product

Measure: FirstSortedValue(distinct Customer, -Sales)

 

At least based on the sample data, I'm not sure why you need that messy aggr() in there.

 

Somsok
Contributor
Contributor
Author

@Or Thank you for the input! 
My Data table is highly simplified. In the real case I will have multiple rows of the same Customer and Product I want to sum up. Your solution works if I want to display the Customer with the highest single order. However, I want to see which Customer has the highest order total.

I found a working solution for me:
FirstSortedValue(distinct Customer, -Aggr(sum(Sales), Customer, Product), 1)
I just had to also include the Product in the Aggr statement.