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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Dax to find the producttype purchased by a customer

I want to find the producttype for a given customer. I have 3 tables that are as follows:

customerID

customername

1

a

2

b

3

c

ProductID

SalesCustomerID

1000

3

1004

3

1009

3

2000

1

1007

1

1002

1

1005

2

1003

2

ProductIDProductcategoryProducttype
1000Product1new
1002Product1existing
1003Product1new
1004Product2existing
1005Product1new
1006Product2new
1007Product1existing
1009Product1existing
2000  

The customer and sales table are related by customerID-SalescustomerID and the sales and product table are related by productID.

 If the customer has purchased different producttypes then producttype should be 'mixed' else the producttype should be populated. Output excpected:

CustomerIDCustomernameProducttype
1aexisting
2bnew
3cMixed

Thanks in advance.

 

 

 

 

 

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

In Table2 (Sales), write this calculated column formula

Product Type = related(product[producttype])

Create a Tabel visual and drag the 2 fields from Table1 to the visual.  Write this measure

Measure = if(distincount(Sales[product type])>1,"Mixed",max(Sales[product type]))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

In Table2 (Sales), write this calculated column formula

Product Type = related(product[producttype])

Create a Tabel visual and drag the 2 fields from Table1 to the visual.  Write this measure

Measure = if(distincount(Sales[product type])>1,"Mixed",max(Sales[product type]))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Thanks for your reponse!!!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
FrankAT
Community Champion
Community Champion

Hi @Anonymous ,

with your sample data you can do it like this:

 

21-04-_2021_23-16-08.png

 

21-04-_2021_23-15-21.png

 

Producttypes = 
VAR _Prototype = CONCATENATEX(VALUES(Table3[Producttype]),Table3[Producttype],", ")
VAR _LenFull = LEN(_Prototype) 
VAR _LenShort = LEN(SUBSTITUTE(_Prototype,",",""))
VAR _CountOfPrototypes = _LenFull - _LenShort + 1
RETURN
    IF(_CountOfPrototypes > 1 , "Mixed", _Prototype)

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.