Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Will1
Contributor
Contributor

Aggr() function with ranking in a line chart

Hi everyone - HELP! I am trying to create something similar to the line chart below created in excel. This contains a line for average sales for each year by year for the top 2 area rankings across 3 years.

Will1_0-1632845616680.png

The rolled up data below is the sum of sales for all 3 years. So Areas A & E should be included in the line chart.

AreaSalesRank
A2,948,491.202
B2,038,385.954
C2,023,691.535
D2,735,826.863
E3,364,687.011

 

I want to be able to include lines on the chart for the top 2 rankings. In reality, there are a lot more Areas, but I have simplified the data.

The aggregated data that needs to be included in the line chart for the top 2 rankings is below. In reality, there are 4 years, but I have simplified the data.

I started with this - 

Aggr(Sum(Sales)/count({$ <SalesFlag={"Yes"}>}SalesFlag),Year)

Count is based on SalesFlag being "Yes". "No"'s are ignored.

I have not figured out how to add Area into the AGGR() function. I keep getting nothing back.

AreaYearSalesCountAverage Sale
A2018686,149.9940       17,153.75
A20191,388,791.9240       34,719.80
A2020873,549.2940       21,838.73
B2018876,765.2221       41,750.72
B2019665,434.1021       31,687.34
B2020496,186.6321       23,627.93
C2018197,548.4311       17,958.95
C2019518,430.4011       47,130.04
C20201,307,712.7011     118,882.97
D2018976,574.6937       26,393.91
D2019646,155.9837       17,463.68
D20201,113,096.1937       30,083.68
E2018922,409.0251       18,086.45
E20192,058,917.6951       40,370.94
E2020383,360.3051         7,516.87

 

The data attached has had the No sales removed for all years and areas.

Should I be using the aggr() function? if not, what should I use?

Thank you for any help you can offer.

0 Replies