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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

Count customers with just two products. Filter specific combinations

I will try to explain my challenge.

 

I have a table "All Customers" with the following columns (among others):

NAME

PRODUCT


I created another Table "Total Products by Customer". All I did was group by "NAME" and the new column "NUMBER OF PRODUCTS" is just a count, so now I know how many products each customer have:

NAME (Unique)

NUMBER OF PRODUCTS 

 

These two tables are related by NAME on a Both Cross Filter direction

 

I want to calculate a measure to know how many customers just have the combination of Product1(P1) and Product2(P2). I have tried many things this is the latest:

 

Number of Customers with 2 Major Products = CALCULATE(DISTINCTCOUNT('All Customers'[NAME]),AND(AND(AND('All Customers'[PRODUCT]<>"P3",'All Customers'[PRODUCT]<>"P4"),'All Customers'[PRODUCT]<>"P5"),'All Customers'[PRODUCT]<>"P6")) 

 

I also added a slicer to filter just those with two products. The result I am getting includes or counts customers that have P1 and P2, and any combination of either P1 or P2 with other product. 2MP.jpg

 

 

 

 

 

 

 

 

 

 

 

I hope I was clear on my explanation.

 

Any help will be highly appreciated

1 ACCEPTED SOLUTION
MalS
Resolver III
Resolver III

I am sure there is a smart way to do this with DAX expressions, but there is also a trick you can use with calculated columns...

 

Edit Queries, then in "All Customers" go to Add Column > Custom Column and enter a formula like this:

 

 

 

Product Check = if [Product] = "P1" then "1" else if [Product] = "P2" then "10" else "100"

Now group by name, and create a new column by summing the Product Check column. You should see a list of names, and every name on that list where Product Check = 11 owns P1 and P2 and nothing else. 

View solution in original post

2 REPLIES 2
MalS
Resolver III
Resolver III

I am sure there is a smart way to do this with DAX expressions, but there is also a trick you can use with calculated columns...

 

Edit Queries, then in "All Customers" go to Add Column > Custom Column and enter a formula like this:

 

 

 

Product Check = if [Product] = "P1" then "1" else if [Product] = "P2" then "10" else "100"

Now group by name, and create a new column by summing the Product Check column. You should see a list of names, and every name on that list where Product Check = 11 owns P1 and P2 and nothing else. 

Anonymous
Not applicable

Thank you for your response it worked. I just want to notice it is very important to remember it is case sensitive and the conditional if needs parenthesis. 

Product Check = if ([PRODUCT] = "P1") then "1" else if ([PRODUCT] = "P2") then "10" else "100" 

 

Thank you!!

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors