Forum Discussion
DAX Function for 'Customers also bought'
- 9 years ago
Hi JosephJC
A Basket Analysis pattern will work for this.
http://www.daxpatterns.com/basket-analysis/
Here's a dummy example pbix
First create a 'Filter Product' table with an inactive relationship with your Orders table:
You use the 'Filter Product' table to select the product(s) to be analysed.
Then, assuming you have created your base measures for Quantity/Price etc, you create 'basket analysis' measures with this pattern (taken from DAX Patterns):
Order Quantity for Customers who bought Filter Product = CALCULATE ( [Order Quantity], CALCULATETABLE ( SUMMARIZE ( Orders, Orders[Customer] ), ALL ( Orders[Product] ), USERELATIONSHIP ( Orders[Product], 'Filter Product'[Filter Product] ) ) )This measure will return the Order Quantity for any Products purchased by Customers who purchased the products selected in 'Filter Product'.
Hopefully this or something similar meets your needs.
Cheers,
Owen
I want the filter production selection that i make on the slicer to not show up on table that i return afterwards.
E.g. i want to see all OTHER products in the baskets that contain product X , but not show product X itself.
Right now when i click for example "pants", It might say
Pants : 5
Socks : 3
Shoes : 2
Hats : 1
I want it to just say
Socks : 3
Shoes : 2
Hats : 1
(Product X is actually going to be a long selection in my model, but should be similar solution)
Sure thing 🙂
I have updated my sample PBIX with an example - attached.
In this model, I have also created 'Product' and Customer dimensions to better represent a typical model, and adjusted the measures accordingly.
Here is one of the new measures, that returns Quantity for Customers who bought the selected "Filter Products", but only for products other than the selection:
Order Quantity for Customers who bought Filter Product (excl Filter Product) =
CALCULATE (
[Order Quantity],
CALCULATETABLE (
SUMMARIZE ( Orders, Customer[Customer] ),
ALL ( 'Product' ),
USERELATIONSHIP ( Orders[Product], 'Filter Product'[Filter Product] )
),
KEEPFILTERS (
EXCEPT (
VALUES ( 'Product'[Product] ),
VALUES ( 'Filter Product'[Filter Product] )
)
)
)
Regards,
Owen
- AlexaderMilland4 years agoHelper III
Works like a charm!
- WettenVamos3 years agoFrequent Visitor
Hi Owen,
I have a similar problem with subscription. I think your solution will work fine, but i need an extra check. Subscription have a start and an end date, and i want to check if the subscription were active during the same period.
Can you help me?
- OwenAuger3 years agoSuper User
Hi WettenVamos
Yes, I think I can help with that.
Just to confirm the requirements:
Comparing with the example above, rather than "Products" you have "Subscriptions".
Each Subscription has a start & end date.
Any given customer may have purchased multiple Subscriptions
Then (as an example) you want to be able to see for customers that purchased Subscription A, which other Subscriptions did they purchase, as long as the Subscriptions overlap in time?
Could you show what your tables or data model look like?
Regards,
Owen