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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
Employee
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
Employee
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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.