I need to create a report that gives a count of customers who have purchased a certain product (or products) but NOT purchased another other product (or products). I have 3 products, A, B, C amongst a sales table of many more products.
Bought A only - 200 customers
Bought B only - 50 customers
Bought C only - 65 customers
Bought A and B (but not C) - 156 customers
Bought A and C (but not B) - 90 customers
bought B and C (but not A) - 33 customers
Bought A, B and C - 23 customers
I do not need to show all counts at once, I have created a filter for the products and a card to show the customer count:
For simplicities sake of the example, this is the table structure:
What makes it more complicated is that I am using a live connection to an Azure Analysis Services tabular model so cannot use Calculated Tables or Calculated Columns.
I started by creating a static table (within my model) for the selectable products A, B and C and wrote a measure but realised it was only taking into account products people had bought based on the filter selection and wasn't factoring in products they hadn't bought.
I am new to DAX and finding it tricky dealing with having to create tables on the fly within my measure and not really be able to see what is happening!
If anyone can help it would be great. Thanks in advance.
The model isn't as simple as in the image from the question, I do have Customer, Sale, Product tables with required relationships. I have also created a static table containing the Product Keys for the 3 products I am interested in.
Even with these tables however I am still not sure how I can set up the measure count the customers who have sales for products for those selected, and do not have a sale for any products not selected.
Thanks for the link @Vvelarde. I took a look but I couldn't manage to change it to what I needed. I have come up with a working solution which doesn't feel particularly elegant but it is returning the results I need:
I create a table for each customer and then whether they have a sale for each of my products I care about. I then filter on that table checking for sales and which filters are selected, with a filter for each of the 7 combinations of results I want to return giving I only care about 3 products. It's clearly very hard-coded and wouldn't really be feasible for any more than 3 products due to the number of combinations but it does work.
If anyone happens can offer a more elegant solution then I would be very happy to learn a better way of doing this in future!
Hi, I loved your solution on the problem. I am trying to solve the same problem for my org. It is just I have "Sub Product" as well. I have one more add into your solution, if you can tell me, how can I add a measure or caculated column such that it can show me what items are missing.
for instance in your example pbix file, Client Fred has bought only Product "A" but Fred is missing Product B,C,D,E.
I want to show that in a seperate table. Please help me in how I can modify it.