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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.