cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

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"
1 ACCEPTED SOLUTION
Super User IV
Super User IV

@TGB - Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.

 


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
Super User IV
Super User IV

@TGB - Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.

 


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Hi, 

 

I found the solution in one of the links. I made a mistake with linking the data.

Helpful resources

Announcements
secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

Wave Release 2

Check out the updates in Power BI.

Overview of Power BI 2020 release wave 2!

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors