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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
ilovedataviz123
Regular Visitor

How to display a Matrix to find out count of unique ids that had two categories?

Hi,

 

I have a simple table for sample:

IDCategory
1A
1B
1C
2A
3D
3C
4B

 

I basically want a matrix like this

 

 ABCD
A2 (100%)1 (50%)1 (50%)0 (0%)
B1 (50%)2 (100%)2 (50%)0 (0%)
C1 (50%)1 (50%)2 (100%)1 (50%)
D0 (0%)0 (0%)1 (100%)1 (100%)

 

I would either like the unique counts of ids or a percetange. 

 

The results could be interpreted like this: How many times was a column category used in an "id" when the row category was used?

For ex: When D category was used, C was also used hence you see in row D the counts for column C and D and 1 and similarly for others.

 

I am looking for any advice on how to achieve this or how to model my data to achieve this output!

 

Thanks!

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @ilovedataviz123 ,

 

Create a new table with the categories (this need to be a disconnecte table no relationships) then add the following measure to your model:

Category count =
VAR CategoryValue =
    SELECTEDVALUE ( 'Table'[Category] )
VAR temptable =
    SELECTCOLUMNS (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Category] IN DISTINCT ( Categories[Category] )
        ),
        "DDD", 'Table'[ID]
    )
VAR IDSelection =
    FILTER ( ALL ( 'Table' ), 'Table'[ID] IN temptable )
VAR _TextValues =
    CONCATENATEX ( IDSelection, 'Table'[Category] )
RETURN
    LEN ( _TextValues ) - LEN ( SUBSTITUTE ( _TextValues, CategoryValue, "" ) )

Now use the categories from the current table on the rows and the one from the new table on the  columns:

MFelix_0-1675261777680.png

 

 

The percentages is just selecting to show values has GT of rows:

MFelix_1-1675261801924.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





View solution in original post

1 REPLY 1
MFelix
Super User
Super User

Hi @ilovedataviz123 ,

 

Create a new table with the categories (this need to be a disconnecte table no relationships) then add the following measure to your model:

Category count =
VAR CategoryValue =
    SELECTEDVALUE ( 'Table'[Category] )
VAR temptable =
    SELECTCOLUMNS (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Category] IN DISTINCT ( Categories[Category] )
        ),
        "DDD", 'Table'[ID]
    )
VAR IDSelection =
    FILTER ( ALL ( 'Table' ), 'Table'[ID] IN temptable )
VAR _TextValues =
    CONCATENATEX ( IDSelection, 'Table'[Category] )
RETURN
    LEN ( _TextValues ) - LEN ( SUBSTITUTE ( _TextValues, CategoryValue, "" ) )

Now use the categories from the current table on the rows and the one from the new table on the  columns:

MFelix_0-1675261777680.png

 

 

The percentages is just selecting to show values has GT of rows:

MFelix_1-1675261801924.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.