The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
I need help with one of my projects on frequent bought products:
My requirement is to fetch products which are bought in same order frequently with the selected products in the slicer. Similar to the Recommendation Engine in Ecommerce sites which provides the insight on ‘Customers also purchased this Product combinations’.
Tables Orders
Table Filter Product
Data Modelling:
Slicer Selection - X, Y (Filter Product)
Expected -
Actual -
Formula I used for Quantity and Price is :
I tried several logics, but nothing seems to be working. Is there anyway someone could help me with the logic?
Solved! Go to Solution.
For future reference, the solution that worked in my case is provided below. Updated my Order Quantity and Price logics, please find teh updated logic below:
Order Quantity for Customers who bought Filter Product =
VAR _selected=DISTINCT('Filter Product'[Filter Product])
VAR __Orders = SELECTCOLUMNS(FILTER(DISTINCT(Orders[Order No]),
CALCULATE(DISTINCTCOUNT(Orders[Product]),TREATAS( _selected, Orders[Product])) = COUNTROWS(_selected)
),"__Order",[Order No])
RETURN CALCULATE ([Order Quantity],FILTER(Orders,[Order No] IN __Orders) )
Price for Customers who bought Filter Product =
VAR _selected=DISTINCT('Filter Product'[Filter Product])
VAR __Orders = SELECTCOLUMNS(FILTER(DISTINCT(Orders[Order No]),
CALCULATE(DISTINCTCOUNT(Orders[Product]),TREATAS( _selected, Orders[Product])) = COUNTROWS(_selected)),"__Order",[Order No])
RETURN
CALCULATE ([Revenue],FILTER(Orders,[Order No] IN __Orders))
Output now getting as expected:
For future reference, the solution that worked in my case is provided below. Updated my Order Quantity and Price logics, please find teh updated logic below:
Order Quantity for Customers who bought Filter Product =
VAR _selected=DISTINCT('Filter Product'[Filter Product])
VAR __Orders = SELECTCOLUMNS(FILTER(DISTINCT(Orders[Order No]),
CALCULATE(DISTINCTCOUNT(Orders[Product]),TREATAS( _selected, Orders[Product])) = COUNTROWS(_selected)
),"__Order",[Order No])
RETURN CALCULATE ([Order Quantity],FILTER(Orders,[Order No] IN __Orders) )
Price for Customers who bought Filter Product =
VAR _selected=DISTINCT('Filter Product'[Filter Product])
VAR __Orders = SELECTCOLUMNS(FILTER(DISTINCT(Orders[Order No]),
CALCULATE(DISTINCTCOUNT(Orders[Product]),TREATAS( _selected, Orders[Product])) = COUNTROWS(_selected)),"__Order",[Order No])
RETURN
CALCULATE ([Revenue],FILTER(Orders,[Order No] IN __Orders))
Output now getting as expected:
Hi , is there anyway to optimise this query?
Hi @Anonymous - The relationship appears to be inactive, so it will not apply the filter. Consider adding the following measure:
CALCULATE ( [Count] , USERELATIONSHIP( 'Orders'[Product] , 'Filtered Products'[Filtered Product] ))
Hi @Daryl-Lynch-Bzy,
I tried your measure formula, but its not working. It is only fetching selected products. my requirement is to fetch products which are bought in same order frequently with the selected products in the slicer. In my case it should be X, Y and Z with there order quantity and Total Price. please see the output screenshot from the dax : CALCULATE ( [Count] , USERELATIONSHIP( 'Orders'[Product] , 'Filtered Products'[Filtered Product] ))
@Anonymous Customer A bought X, Y and also W so I guees the result you get are correct because customer bought X, Y, W and customer B bought X, Y , Z. If you want to get you need, you have to introduce a condition to your formula where the Order No needs to be the same, like:
Your measure =
CALCULATE ( SUM ( 'Orders'[Quantity] ), [Order No] = EARLIER ( [Order No] ) )
Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudoe 👍
Thanks!
You can also check out my LinkedIn!
Best regards,
Gonçalo Geraldes
Hi @goncalogeraldes,
Customer A bought X, Y and also W but in separate orders. If I am selecting X and Y, it should only give XY and Z in the outcome as they are bought in same order.
User | Count |
---|---|
15 | |
13 | |
8 | |
6 | |
6 |
User | Count |
---|---|
24 | |
19 | |
12 | |
9 | |
7 |