Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
amber2000
Creator
Creator

Count Distinct or Count Aggr doesn't return correct values

Hi all,

I'm having difficulties to use a Count distinct() or Count Aggr()

My table haas duplicate values on column SD_Dest_Pallet.

I want to count the Distinct SD_Dest_Pallet's per Date/Aisle_Facturation/Shop_Ens/

Even the simple sum of SD_Shipped_Colli isn't correct, I'll always get 5 colli to much

In my example (that's attached) I'm using only 1 Aisle_Facturation and 1 Shop_Ens tot test the expressions.

I've a chart with a distinct(Count) and another chart with a Aggr (count)

These are the correct values that should be presented in Qlikview:  

SD_Close_DateAisle_FacturationShop_Ens#Colli#PalletColli / Pal Uit
20160331PBL_OVERIGEPricelist_Hyper401580,20
20160401PBL_OVERIGEPricelist_Hyper5911059,10
20160402PBL_OVERIGEPricelist_Hyper341568,20
20160404PBL_OVERIGEPricelist_Hyper396579,20
20160405PBL_OVERIGEPricelist_Hyper10156169,17
20160406PBL_OVERIGEPricelist_Hyper328565,60
20160407PBL_OVERIGEPricelist_Hyper5000,00
TOTAL31223686,72

Does anyone see where the problem is situated in my example please???

Monique

1 Solution

Accepted Solutions
swuehl
MVP
MVP

I think you should fix this in your data model.

You can create a flag that indicates the first SD_Close_Date for each pallet, which you then can use to filter in your set expression.

You can create a temporary table with min SD_Close_date and the flag field grouped by an appropriate key (maybe just SD_Dest_pallet), then join this flag back to your facts table.

You can also consider modifying your data model so that you get read of your pallets duplicates, which should simplify your aggregation.

Since we don't know anything about your model or requirement in detail, it's hard to be more specific.

View solution in original post

12 Replies
sunny_talwar

You aggr solution seems to be working, not sure what the issue is?

Capture.PNG

swuehl
MVP
MVP

Doesn't the Aggr() chart show exactely these numbers?

amber2000
Creator
Creator
Author

Sorry Guys,

I gave the wrong example, that's a simple chart and there it works fine.

In a complex chart It's another story.

I'll send a correct attach of the complex example showing the wrong values.

sunny_talwar

Ya unless we are able to see the issue, it would be difficult to propose a solution

amber2000
Creator
Creator
Author

This is the example with the wrong values.

Both charts show different results and both are wrong results

swuehl
MVP
MVP

If you want to count something per multiple dimensions, you should use these dimensions in the aggr() dimensions as well...

= Count({$ <[SD_WH] -= {12}, [Aisle_Zone] -= {PBS_Containers, PBS_Displays}> }aggr(count([Aisle_Facturation]), SD_Dest_Pallet))

Add your charts dimensions to the aggr() dimension list.

And probably you need to use Sum() as your outer aggregation.

sunny_talwar

What is the correct output you are hoping to see?

swuehl
MVP
MVP

Yes, would be helpful to know the expected ouput.

Maybe this?

= Sum({$ <[SD_WH] -= {12}, [Aisle_Zone] -= {PBS_Containers, PBS_Displays}> }

aggr(

count({$ <[SD_WH] -= {12}, [Aisle_Zone] -= {PBS_Containers, PBS_Displays}> }[Aisle_Facturation])

, [$(=GetCurrentField( Aisle ))] ,[$(=GetCurrentField( Enseigne ))], [$(=GetCurrentField(  Periods ))]

))

1) Sum as outer aggregation

2) set expression used in both aggregations (not sure if you need to modify

3) full list of dimensions to group by.

Do you also need a count distinct here?

Not sure, missing the expected result or full description of logic.

amber2000
Creator
Creator
Author

The Output that I showed in my initial question:

   

SD_Close_DateAisle_FacturationShop_Ens#Colli#PalletColli / Pal Uit
20160331PBL_OverigePricelist_Hyper401580,20
20160401PBL_OverigePricelist_Hyper5911059,10
20160402PBL_OverigePricelist_Hyper341568,20
20160404PBL_OverigePricelist_Hyper396579,20
20160405PBL_OverigePricelist_Hyper10156169,17
20160406PBL_OverigePricelist_Hyper328565,60
20160407PBL_OverigePricelist_Hyper5000,00