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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Selecting unique shoppers in dataset

Hello Community,

I have a challenge I am hoping for some help to get started on

I have four relevant tables:

Fact Sales

Dim Category

Dim Product
Dim Users

DimCategory is structured as follows:
Category > Level 1 > Level 2 > - .. - > Level 5

 

I am looking to write a DAX measure where I can select a product (Dim Product) and then display a count of users who have bought the specific product but who has not bought any other products from the selected products category level.

So far I believe I need to use CALCULATETABLE() and then alter the filter context to exclude the users who fail the test but I am not sure how to structure it

4 REPLIES 4
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

Thanks for reaching out to us.

>> I am looking to write a DAX measure where I can select a product (Dim Product) and then display a count of users who have bought the specific product but who has not bought any other products from the selected products category level.

could you give an example? based on the sample data below, if I select Category=A, Product=T1, then expected output= (?)

vxiaotang_0-1663140431461.png

 

 

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thank you for your reply, I have adapted your sample data a little to answer the confusion:

escapethisscree_0-1663230528700.png

 

amitchandak
Super User
Super User

@Anonymous , a new measure , will give count of category where you got selected product not any other product

 

measure =

var _sel = allselected(product[Product])

var _cat = summarize(filter(allselected(Product), product[Product] in _sel) , Product[Category])

return

countx(filter(summarize(Fact, Product[Category], "_1", countrows(Fact), "_2", calculate(countrows(Fact), filter(Product, Product[Category] in _cat && not( product[Product] in _sel) ) ) ), not(isblank(_1)) && isblank(_2)),[Category])

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thank you very much for your great reply. I have tried building out the measure like you suggested but am getting an error:

 

 

VAR _selProd = ALLSELECTED( Product[Brand] )

VAR _Cat = SUMMARIZE(FILTER(ALLSELECTED('Product'), 'Product'[Brand] IN _selProd), 'Product'[CategoryId])

RETURN
    
    COUNTX(
        FILTER(
            SUMMARIZE(
                Purchase, Product[CategoryId],
                "_1", COUNTROWS( Purchase ), "_2",
                CALCULATE(
                    COUNTROWS(
                        Purchase
                    ), FILTER(
                        'Product',
                        'Product'[CategoryId] IN _Cat && NOT(Product[Brand] IN _selProd)                                               
                    )
                )
            ), NOT ( ISBLANK( "_1" ) )
                    && ISBLANK( "_2" )
                ), Product[CategoryId]
            )

 

 

 I changed the formula because I discovered an error. I am no longer getting an error but I am not getting any values

Edit: DAX formula changed because of an error

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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