cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
UrosB Frequent Visitor
Frequent Visitor

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 Frequent Visitor
Frequent Visitor

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

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 Frequent Visitor
Frequent Visitor

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"

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 Frequent Visitor
Frequent Visitor

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

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 Frequent Visitor
Frequent Visitor

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])

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

UrosB Frequent Visitor
Frequent Visitor

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
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors