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
Anonymous
Not applicable

Count of Distinct Subcategory Occurence

Hi All,

I am trying to set up a measure that only counts the total subcategory count of items that have been ordered. I have two key tables and a fact table

 

Category Key Table

CategoryCategory Key
Accessory1
Bike2
Clothing3

 

 Subcategory Key Table

CategorySubcategory

Subcategory

Key

Category Key
AccessoryHelmet11
AccessoryBottle21
AccessoryBike Rack31

Bike

Wheel42
BikeChains52
ClothingGloves63
ClothingJersey73

 

 

Order #CategoryCategory KeySubcategorySubcategory KeyOrdered (Y/N)
44455Accessory1Helmet1Y
44455Accessory1Bike Rack3Y
44455Accessory1Wheel4Y
22233Bike2Chains5Y
22233Bike2Wheel4Y
22233Clothing3Gloves6Y
11199Clothing3Wheel4Y
11199Clothing3Jersey7

Y

 

The data is taken from an excel tracker which looks like the above fact table when transformed.

 

If I were to create a count of the subcategory (total items ordered) I would return 8, which is incorrect. The category key, subcategory key, and master fact table are all linked. I would only want to return a count of those subcategory items that are correctly associated in the subcategory key table to the correct category key, which should give me a count of total items based off of the master table. 

 

Currently, my DAX is set up to be: Total Subcategory Count = Calculate(Count(Order ID), [Ordered] = "Y")

 

Is there some way for the DAX to be set up where it only counts the subcategory key if it's correctly associated with the right category key?

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Please try:

Total Subcategory Count = CALCULATE(DISTINCTCOUNT('Table'[Subcategory Key]),'Table'[Ordered (Y/N)] = "Y")

vcgaomsft_0-1674031040824.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous ,

 

Please try:

Total Subcategory Count = CALCULATE(DISTINCTCOUNT('Table'[Subcategory Key]),'Table'[Ordered (Y/N)] = "Y")

vcgaomsft_0-1674031040824.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.