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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
paulenomial
Frequent Visitor

Filtering Customers based on Sales in Different Categories

Our organisation is new to Power BI and I'm trying to do some things that we were able to do in our previous BI software. I've been banging my head against the wall trying to do the below.

 

I'm trying to create a measure that shows the quantity sold of a certain category of item, but to only include customers who have never bought items from another, separate category. See some sample data below:

 

Sales numberDateCustomerCategoryQuantity
SO-0000000101/01/2022Customer 1Category A100
SO-0000000201/01/2022Customer 1Category B50
SO-0000000301/02/2022Customer 2Category A65
SO-0000000401/03/2022Customer 2Category C70

 

For example, say I wanted sales of items in category A for customers who have never bought anything in category B. The measure should disregard Customer 1 (as sales from Category B are non-zero for that customer) but include Customer 2 - though only show sales for Category A. The measure should therefore show a quantity of 65 in this case.

 

Thanks in advance for any help.

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Here is a measure expression you can use. Replace Sales2 with your actual table name.

 

No Cat B Sales =
VAR NoBSales =
    FILTER (
        DISTINCT ( Sales2[Customer] ),
        ISBLANK (
            CALCULATE ( COUNT ( Sales2[Customer] ), Sales2[Category] = "Category B" )
        )
    )
RETURN
    SUMX (
        NoBSales,
        CALCULATE ( SUM ( Sales2[Quantity] ), Sales2[Category] = "Category A" )
    )

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

Interesting one to solve.  Considering there will be many customers and categoies, hard coding the Category in the measure will not be a viable solution.  Could you share more rows of data in your sample please.  I'd like to try something.

Thank you. 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
mahoneypat
Microsoft Employee
Microsoft Employee

Here is a measure expression you can use. Replace Sales2 with your actual table name.

 

No Cat B Sales =
VAR NoBSales =
    FILTER (
        DISTINCT ( Sales2[Customer] ),
        ISBLANK (
            CALCULATE ( COUNT ( Sales2[Customer] ), Sales2[Category] = "Category B" )
        )
    )
RETURN
    SUMX (
        NoBSales,
        CALCULATE ( SUM ( Sales2[Quantity] ), Sales2[Category] = "Category A" )
    )

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thank you, Pat. That looks to be working well - I didn't even think of trying a distinct count in that way.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors