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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors