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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
hyggins
Helper I
Helper I

How to create COUNT() measure based on multiple criteria?

I have the following tables:

Customers – list of customers

Customer States – many to many relationships of customers and operating states

Customer Categories – many to many relationships of customers and operating categories

Customer Options – list of options available to customers by State and Category combination

 

Tables.png

I need a measure that will count options by customer id based on their states and categories

See sample output with matching IDs for reference

 

Output.png

How do I create/design the relationships to facilitate such a measure?

What would the actual measure code look like?

 

Thank you!

1 ACCEPTED SOLUTION

Hi @hyggins ,

 

You could merge these tables with "Inner Join" to get a new table "Merge1".

Then use the following measures to get result.

 

Count =
CALCULATE (
    COUNT ( Merge1[Customer Category Id] ),
    ALLEXCEPT ( Merge1, Merge1[Customer Id] )
)
Option Ids =
CONCATENATEX ( Merge1, Merge1[Option Id], "," )

 

Here is the result.

1-1.PNG

Here is my test file for your reference.

 

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

View solution in original post

5 REPLIES 5
v-eachen-msft
Community Support
Community Support

Hi @hyggins ,

 

I still don't understand your expected result.

For example, Customer 1 have 2 states : NY & CA, 1 category : A. So I get 101,106,109,110. It is different from your result which you just keep NY. So, do you have any other relationships not mentioned?

3-1.PNG

 

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

Hello @v-eachen-msft ,

 

It seems you understand my data better than I do. My apologies for the incorrect results table. See below for update.

 

Count of Custom Options Results
CustomerCountOption Ids
14101, 106, 109, 110
26102, 103, 106, 109, 112, 113
32108, 111
47101, 104, 105, 106, 107, 109, 110

 

Regarding additional relationships, I do have an OptionsDim and CategoriesDim but didn't think that factored in.

 

I'm also reposting the table at @Greg_Deckler 's request.

Customers
Customer Id
1
2
3
4

 

Customer States
Customer IdCustomer State Id
1NY
1CA
2GA
2KY
2CA
3TX
4WI
4NY
4CA

 

Customer Categories
Customer IdCustomer Category Id
1A
2A
2B
3B
4A
4C

 

Customer Options
Option IdState IdCategory Id
101NYA
102CAB
103GAA
104NYC
105WIA
106CAA
107NYC
108TXB
109CAA
110NYA
111TXB
112GAB
113KYA

 

Thank you!

Hi @hyggins ,

 

You could merge these tables with "Inner Join" to get a new table "Merge1".

Then use the following measures to get result.

 

Count =
CALCULATE (
    COUNT ( Merge1[Customer Category Id] ),
    ALLEXCEPT ( Merge1, Merge1[Customer Id] )
)
Option Ids =
CONCATENATEX ( Merge1, Merge1[Option Id], "," )

 

Here is the result.

1-1.PNG

Here is my test file for your reference.

 

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

Hello @v-eachen-msft 

 

Thank you so much for your suggestions!

 

Your ideas lead me to the result I was looking for. I appreciate your time!

 

 

Greg_Deckler
Super User
Super User

Can you post the data as text so we do not have to type it all in by hande?

 

Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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