cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dmitry-wbr
Regular 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!

3 REPLIES 3
Jihwan_Kim
Community Champion
Community Champion

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

amitchandak
Super User IV
Super User IV

@dmitry-wbr , Try a measure like

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



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

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
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are You Ready?

Test your skills now with the Cloud Skills Challenge.

Top Solution Authors