Qlik Community

Ask a Question

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

Announcements
Welcome to our newly redesigned Qlik Community! Read our blog to learn about all the new updates: READ BLOG and REPORTED ISSUES
cancel
Showing results for 
Search instead for 
Did you mean: 
Contributor III
Contributor III

total stock kpi

Hello,

I need some help for a specific KPI, please!

I have something like that:        

material idwarehouse idstock [pieces]date
1a100

9.12.2019

1a508.12.2019
1b1008.12.2019
1c1008.12.2019
2a1008.12.2019

 

Now I want to calculate the total stock, but only for the latest date for each warehouse and material. So if there are 2 different stocks on a different date but in the same warehouse and for the same material, only the latest counts. 

For this example, the result should be:
for material 1: 300
for material 2: 100
total: 400

 

I've tried something like that "sum(aggr(stock_pieces, material_id, warehouse_id, inventory_date))" but it shows 450 because I do not know how to pick only the latest date.

 

Thanks for your help!

 

1 Solution

Accepted Solutions
Specialist
Specialist

Hi,
something like;
sum(aggr(FirstSortedValue(stock,-date),[material id],[warehouse id]))
Cheers, Chris.

View solution in original post

2 Replies
Specialist
Specialist

Hi,
something like;
sum(aggr(FirstSortedValue(stock,-date),[material id],[warehouse id]))
Cheers, Chris.

View solution in original post

Contributor III
Contributor III

Hi Chris,

thank you so much, it works!