cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Anonymous
Not applicable

## Pivot table and create co-occurencies heatmap

I have the following table

 RECORD_ID TAG 1 TAG1 1 TAG2 2 TAG1 2 TAG3

I would like to get a heatmap of co-occurrencies. In matrix form, it would be

 TAG1 TAG2 TAG3 TAG1 count of record_id with tag1 count of record_id with tag1 and tag2 count of record_id with tag1 and tag3 TAG2 count of record_id with tag2 and tag1 count of record_id with tag2 count of record_id with tag2 and tag3 TAG3 count of record_id with tag3 and tag1 count of record_id with tag3 and tag2 count of record_id with tag3

which, in this case, is a symmetric matrix. Then I would like to color the cell based on the value.

I guess to obtain that matrix I should pivot my table on TAG and use those counts as values, but I am not familiar with PowerBi and DAX, so how can I achieve this? and how can I get the coloured heatmap? Is there a more direct way to achieve my goal?

1 ACCEPTED SOLUTION
Super User

@Anonymous - See PBIX attached below sig. Tables (31) and (31a). First, create disconnected table from original like this:

``Table (31a) = DISTINCT('Table (31)'[TAG])``

Then this measure:

``````Measure 31 =
VAR __Table1 = SELECTCOLUMNS('Table (31)',"Record",[RECORD_ID])
VAR __Table2 = SELECTCOLUMNS(FILTER(ALL('Table (31)'),[TAG]=MAX('Table (31a)'[TAG])),"Record",[RECORD_ID])
RETURN
COUNTROWS(INTERSECT(__Table1,__Table2))``````

Put [TAG] from (31) in Rows of a Matrix, [TAG] from (31a) in Columns, Measure 31 in Values.

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
2 REPLIES 2
Super User

@Anonymous - See PBIX attached below sig. Tables (31) and (31a). First, create disconnected table from original like this:

``Table (31a) = DISTINCT('Table (31)'[TAG])``

Then this measure:

``````Measure 31 =
VAR __Table1 = SELECTCOLUMNS('Table (31)',"Record",[RECORD_ID])
VAR __Table2 = SELECTCOLUMNS(FILTER(ALL('Table (31)'),[TAG]=MAX('Table (31a)'[TAG])),"Record",[RECORD_ID])
RETURN
COUNTROWS(INTERSECT(__Table1,__Table2))``````

Put [TAG] from (31) in Rows of a Matrix, [TAG] from (31a) in Columns, Measure 31 in Values.

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks @Greg_Deckler! may I ask you to elaborate a bit more on what the variable __table2 is? I am not quite sure what happens there, and I'd like to understand the process. Thank you.

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.