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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
UrosB
New Member

Help with filtering/DAX - analyze baskets of shoppers who have a specific product in the basket?

Hi, I have a dataset of shoppers and their purchases. Something like the example table below.
 
I need to do basket analysis of shoppers who have bought a specific item, e.g. Item 1 in the example. That means that for my analysis I need to include shoppers 1&3 and all their purchases (items), but omit shopper 2 and all his items.
 
I'm struggling to find a scalable way of doing this, without hard coding anything. Ideally I need a slicer to select a product i.e. shoppers of that specific product to do further analysis.
 
Thanks, Uros
 
ShopperItem
shopper 1item 1
shopper 1item 2
shopper 1item 3
shopper 2item 3
shopper 2item 4
shopper 2item 10
shopper 2item 11
shopper 3item 1
shopper 3item 10
shopper 3item 14
 
2 ACCEPTED SOLUTIONS
V-lianl-msft
Community Support
Community Support

Hi @UrosB ,
 
This article can help you better understand the principle and solve the related problems in the future.
 
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

an update - inspired by your posts, I was able to find a simple solution. Briefly:

  1. created a "filter table" with shopper ID and item ID
  2. made a relationship between the "shopper" column in the main table and the filter table
  3. by selecting an item in the filter table, I filter only shoppers who have the item in the basket.

This seems to work, thanks big time @V-lianl-msft @littlemojopuppy !

View solution in original post

10 REPLIES 10
V-lianl-msft
Community Support
Community Support

Hi @UrosB ,
 
This article can help you better understand the principle and solve the related problems in the future.
 
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
littlemojopuppy
Community Champion
Community Champion

What exactly do you need to calculate?  Counts of shoppers?  % of total customers?

Thanks for reaching out! I need to calculate: Share of (certain) items, quantity of items bought, whether item X was bought by buyers of Y etc. There are numerious calculations I need, all requiring to be able to filter "shoppers of item X"

I'm assuming that Items will be in a slicer and you could use the SELECTEDVALUE function to reference a selected Item.  Overly simplistic example...and will always return a value of 1

 

CALCULATE(
	DISTINCTCOUNT(Item[ID]),
	Item[ID] = SELECTEDVALUE(Item[ID])
)

 

Let's try out one of your measures...

thanks for the quick feedback. I might be missing something, but I get an error that says "A function 'SELECTEDVALUE' has been used in a True/False expression that is used as a table filter expression. This is not allowed."

Let's have some code to look at

Literally copied your code. Table name is "basket", column with products (items) is "product".  I'm a novice user so thanks for the patience!

 

Test =
CALCULATE(
    DISTINCTCOUNT(basket[Product]),
    basket[Product] = SELECTEDVALUE(basket[Product])

Sorry for the delay in replying...I stepped out for a moment.  Take this.

 

Now can I ask specifically what you want to accomplish and how you might want to present it?  Because filter context may automatically take care of filtering for only selected products (for example, in a matrix, chart, graph or table) and we may simply be over-complicating this.

 

Thanks @littlemojopuppy , this formula works but I'm not there yet.

 

For start, I would like to get the following:

  • % of shoppers buying each item, with the base being only shoppers who bought a specific item (e.g. item 1). 
    • e.g. 55% of shoppers (of item 1) have bought item 2, 33% have bought item 3, 0% have bought item 4 etc

this is one of the metrics. next to items I also have additional item-related variables, like time spent looking at the item. I need to be able to analyze all of these variables. Like buyers of item 1 have spent X amount of time looking at item 2, Y amount of time looking at item 3 etc. This seems a bit different from the usual basket analysis.  

 

Hope this makes sense, thanks!

 

an update - inspired by your posts, I was able to find a simple solution. Briefly:

  1. created a "filter table" with shopper ID and item ID
  2. made a relationship between the "shopper" column in the main table and the filter table
  3. by selecting an item in the filter table, I filter only shoppers who have the item in the basket.

This seems to work, thanks big time @V-lianl-msft @littlemojopuppy !

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.