Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Filter in DAX expression is incorrect

Hi everyone,

 

I'd like to count the number of products of a certain product-type that each customer (ID) ever has bought . For the analysis I need it to be in displayed in a column not a measure.

 

The following DAX expression counts the total number of products sold to a customer correct.

Total products = Calculate( COUNT(SalesProducts[ProductID]) , SalesProducts[CustID] = EARLIER(DataCustomers[CustID]))

 

However, after adding an extra filter (product type) the results are incorrect (too low).

 

Type Wielrennen =
var _WielrennenProducts = GROUPBY( FILTER( DataProducts , DataProducts[LabelSport] = "Wielrennen"), DataProducts[ProductID] )
return
Calculate( COUNT(SalesProducts[ProductID]) , SalesProducts[CustID] = EARLIER(DataCustomers[CustID]), _WielrennenProducts)
 
Type MTB =
var _MTBProducts = GROUPBY( FILTER( DataProducts , DataProducts[LabelSport] = "MTB"), DataProducts[ProductID] )
return
Calculate( COUNT(SalesProducts[ProductID]) , SalesProducts[CustID] = EARLIER(DataCustomers[CustID]), _MTBProducts)
 
Anyone an idea of how I should add the second filter: DataProducts[LabelSport] = "Wielrennen"

2 Replies