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

Using Aggr() in a straight table, aggregation on field not used in table (highest value for third dimension)

Hello,

 

I have a table with Product Type (Dimension1), Produce Value Band (Dimension 2) and Sales (Expression 1).

I'd like to also return the sales team (let's call it Dimension 3, even though it does not exist as a field in the table) with the highest value of sales (Expression 1).

 

I've been trying to do it as follows:

=FirstSortedValue([Sales Team], - Aggr(Sum([Sales Value]), [Sales Team]))

This gives wild results which don't seem to match the data in any logical way; I have taken the max of the aggr expression within and it seems to be more than the total value of sales? So I'm not sure the aggr is doing as it should here, is this because I am using a dimension that doesn't exist in the table? I've also tried NODISTINCT and it doesn't give results expected either. 

Is there something I'm missing here, or is there another way to do this using a different way (give the team with the highest sales results?).

 

Thanks.

 

Labels (3)
1 Solution

Accepted Solutions
Mancunia
Contributor III
Contributor III
Author

OK, I found the issue and if anyone else comes across this, here is the solution. I needed to add the dimension fields from the table into the aggr on top of the extra aggregation (I assumed they would already be aggregated in the level but apparently not). So, it ended up being this:

=FirstSortedValue([Sales Team], - Aggr(Sum([Sales Value]), [Sales Team], [Product Type], [Product Value Band]))

 

 

 

View solution in original post

1 Reply
Mancunia
Contributor III
Contributor III
Author

OK, I found the issue and if anyone else comes across this, here is the solution. I needed to add the dimension fields from the table into the aggr on top of the extra aggregation (I assumed they would already be aggregated in the level but apparently not). So, it ended up being this:

=FirstSortedValue([Sales Team], - Aggr(Sum([Sales Value]), [Sales Team], [Product Type], [Product Value Band]))