Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Oliver1
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
chrismarlow
Specialist II
Specialist II

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

View solution in original post

2 Replies
chrismarlow
Specialist II
Specialist II

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

Hi Chris,

thank you so much, it works!