cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TGB
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
Greg_Deckler
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
Greg_Deckler
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

TGB
Frequent Visitor

Hi, 

 

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

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

March Update

Check it Out!

Click here to read more about the March 2021 Updates!

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.

secondImage

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.