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

sum(sales) for last year of orders in straight table

Hello guys,

I have a problem and I like to illustarte it with some test data. The raw data looks like this:

CustomerSalesDate
A1002.01.2017
A2002.03.2018
A3003.02.2018
B1001.01.2019
B2001.02.2019
C5001.01.2016
C5001.02.2016
C5001.01.2017
C10001.01.2017

 

Now I want the sum(sales) for the year of the particular customer where he had his last order. So the result would look like so:

Customerlast year of orderssum of sales in last year of orders
A201850
B201930
C2017150

 

In Qlik sense I already tried this for last year of orders:

 

max([Date])

 

This works.

 

sum(
{< Year = {'$(=year(max(Date)))'} >}
Sales)

 

This does not. It looks like the set analysis is only evaluated once for the entire table and not based on the customer on the table row. 

So this is what I get:

Customermax(Date)sum({< Year = {'$(=year(max(Date)))'} >}Sales)
A20180
B201930
C20170
Labels (1)
1 Reply
miskinmaz
Creator III
Creator III

This happen because the set analysis try to evaluate the expression for whole chart rather than per rows.

Try to use  sum(aggr(FirstSortedValue( sales,-date),prod_id))