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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
IvanMislav
Helper I
Helper I

Custom calculation based on product categories

Hi,

 

I'm trying to find a way to calculate pecentage of customers that purchased something from a certain group of products. Table example blow:

 

Customer CategoryProductPurchased?
Customer 1FoodAppleTRUE
Customer 1FoodPearFALSE
Customer 1DrinksWaterTRUE
Customer 1DrinksTeaTRUE
Customer 1CosmeticsShampooFALSE
Customer 1CosmeticsDeodorantFALSE
Customer 2FoodAppleTRUE
Customer 2FoodPearTRUE
Customer 2DrinksWaterTRUE
Customer 2DrinksTeaFALSE
Customer 2CosmeticsShampooFALSE
Customer 2CosmeticsDeodorantFALSE
   

 

So, I would like to come up with a measure which would calculate percentage of products bought based on category:

 

  • 100% of the customers purchased FOOD
  • 50% of the customers purchased DRINKS
  • 0% of the customers purchased COSMETICS

It doesnt matter if a customer bought 1 or more products from the same category.

 

Thank you.

 

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @IvanMislav 

 

Try this measure. According to your sample data, 100% of the customers purchased DRINKS rather than 50%.

Measure = 
VAR __allCustomers = CALCULATE(DISTINCTCOUNT('Table'[Customer]),ALL('Table'))
VAR __buyingCustomers = CALCULATE(DISTINCTCOUNT('Table'[Customer]),ALLEXCEPT('Table','Table'[Category]),'Table'[Purchased?]=TRUE())
RETURN
DIVIDE(__buyingCustomers,__allCustomers)+0

063001.jpg

 

Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

View solution in original post

2 REPLIES 2
v-jingzhang
Community Support
Community Support

Hi @IvanMislav 

 

Try this measure. According to your sample data, 100% of the customers purchased DRINKS rather than 50%.

Measure = 
VAR __allCustomers = CALCULATE(DISTINCTCOUNT('Table'[Customer]),ALL('Table'))
VAR __buyingCustomers = CALCULATE(DISTINCTCOUNT('Table'[Customer]),ALLEXCEPT('Table','Table'[Category]),'Table'[Purchased?]=TRUE())
RETURN
DIVIDE(__buyingCustomers,__allCustomers)+0

063001.jpg

 

Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

amitchandak
Super User
Super User

@IvanMislav , Try a measure like

divide(distinctCOUNT(Table[customer]), calculate(distinctCOUNT(Table[customer]), allselected(Table)))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.