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

Totals with NODISTINCT

Hello, everybody!

Sorry for a novice question, but I've been stuck at this for several days and can't figure it out on my own.

We've got a source table like this (very simplified, of course):

StoreSKUStore_StockWH_Stock
Store_1Item_1810
Store_1Item_2320
Store_2Item_1410
Store_2Item_3530
Store_3Item_2620
Store_3Item_3330

 

It contains the stocks of goods at different stores as well as their stocks at the main warehouse (whence the stores are supplied). The values for the warehouse stocks are repeated for each store there the item is present.

So, we need to caculate total stocks across the stores as well as the total stocks at the warehouse - to evaluate how much we can resupply the stores at best. The final table should look like this:

StoreStock_at_StoreStock_at_Warehouse
Store_11130
Store_2940
Store_3950
Total2960

 

But I can't get such figures in QlikView. The stocks at the stores are calculated correctly, but the total for the warehouse stock is doubled:

StoreStock_at_StoreStock_at_Warehouse
Store_11130
Store_2940
Store_3950
Total29120

 

For warehouse stock I'm using the expression:

Sum(aggr(NODISTINCT max(WH_Stock),SKU))

Without NODISTINCT the total becomes correct, but warehouse stocks across stores become wrong (naturally).

 

What am I doing wrong? How can this result be achieved?

Sample QV file is attached.

Many thanks in advance!

 

 

 

 

 

1 Solution

Accepted Solutions
Arthur_Fong
Partner - Specialist III
Partner - Specialist III

Try this:

if(Dimensionality()=0,Sum(aggr( max(WH_Stock),SKU)),
Sum(aggr(NODISTINCT max(WH_Stock),SKU))
)

View solution in original post

2 Replies
Arthur_Fong
Partner - Specialist III
Partner - Specialist III

Try this:

if(Dimensionality()=0,Sum(aggr( max(WH_Stock),SKU)),
Sum(aggr(NODISTINCT max(WH_Stock),SKU))
)

a_yershov
Contributor II
Contributor II
Author

That works, thank you very much!