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
dmitry-wbr
Frequent Visitor

Count distinct number of combinations within groups

Hi all!

I have the following table as a data source in Power BI:

dmitry-wbr_0-1618863815917.png

What I want to do is to see how many unique combinations of categories are there within all groups and sum them up by category. For example, category 3 has 4 total combinations across all groups (0 in group 1 + 2 in group 2 (with categories 1 and 2) + in group 3 (with categories 1 and 2) = 4 combinations in total).
In the end, I want a table that looks like this:

dmitry-wbr_0-1618864769390.png

 

Have been testing various DAX functions in order to achieve that result, but no luck.
Would greatly appreciate your help!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, @dmitry-wbr 

 

Please try the below measure.

 

Count measure =
VAR currentcategory =
MAX ( 'Table'[Category] )
VAR includingcurrentcategory =
VALUES ( 'Table'[Group] )
VAR newtable =
SUMMARIZE (
FILTER (
ALL ( 'Table' ),
'Table'[Group]
IN includingcurrentcategory
&& 'Table'[Category] <> currentcategory
),
'Table'[Group],
'Table'[Category]
)
RETURN
SUMX ( newtable, 1 )

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: https://www.linkedin.com/in/jihwankim1975/

Picture5.png

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi, @dmitry-wbr 

 

Please try the below measure.

 

Count measure =
VAR currentcategory =
MAX ( 'Table'[Category] )
VAR includingcurrentcategory =
VALUES ( 'Table'[Group] )
VAR newtable =
SUMMARIZE (
FILTER (
ALL ( 'Table' ),
'Table'[Group]
IN includingcurrentcategory
&& 'Table'[Category] <> currentcategory
),
'Table'[Group],
'Table'[Category]
)
RETURN
SUMX ( newtable, 1 )

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: https://www.linkedin.com/in/jihwankim1975/

Picture5.png

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


amitchandak
Super User
Super User

@dmitry-wbr , Try a measure like

sumx(values(Table[category]), calculate(distinctCOUNT(Table[group])))

Hi, @amitchandak 
Thanks for the reply! Unfortunately, your formula gives incorrect results. Here is the resulting output (should be 5 for categories 1,2 and 4 for category 3):

dmitry-wbr_1-1618903920049.png

 

 

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.

Top Solution Authors