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
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
- AlexaderMilland4 years agoHelper III
Hi Owen, I know it's an old post but it was quite helpful.
Is there a way to filter out the product you choose in the filter? I want to see all OTHER products (assuming it should work on multiple selections too)
- OwenAuger4 years agoSuper User
AlexaderMilland Glad to hear it 🙂
Just to clarify, since this is a Basket Analysis example, did you want the 'Filter Product' selection to be inverted?
For example, do you want to make the "primary" Product selection on one slicer, then make the 'Filter Product' selection on another slicer, and have a measure that returns Order Quantity for Customers that purchased the "primary" Product selection but not 'Filter Product' selection?
Regards,
Owen
- AlexaderMilland4 years agoHelper III
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)
- Lesliekeziah2 years agoFrequent Visitor
Hi Owen,
Thank you so much for this! I have another question please, what formula should I include to sum up the quantity/product if i selected more than 1 product in the slicer. Thank you.
- OwenAuger2 years agoSuper User
Hi Lesliekeziah
With the measure as it is, selecting multiple products on the slicer will return values for Customers that purchased any of the selected products.
Did you want a different behaviour? Could you provide a small example of the result you're wanting?
- Lesliekeziah2 years agoFrequent Visitor
Hi OwenAuger
Thank you for the reply.Right now when i select two products/items in the slicer, it will calculate separately the sum of the other items sold together (as shown below).
The Result I Wanted: If Selected Items are D & E (multiple products sold together to customers) , Data Will Show
D 21
E 2
F 24
G 14
Hope this makes sense. Thank you so much for your help.