cancel
Showing results for 
Search instead for 
Did you mean: 
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

Accepted Solutions
Microsoft V-lianl-msft
Microsoft

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

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

UrosB
New Member

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

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
littlemojopuppy Continued Contributor
Continued Contributor

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

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

UrosB
New Member

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

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"

littlemojopuppy Continued Contributor
Continued Contributor

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

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...

UrosB
New Member

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

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."

littlemojopuppy Continued Contributor
Continued Contributor

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

Let's have some code to look at

UrosB
New Member

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

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])
littlemojopuppy Continued Contributor
Continued Contributor

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

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.

 

Microsoft V-lianl-msft
Microsoft

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

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

Highlighted
UrosB
New Member

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

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!

 

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors