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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Create matrix visual based on values in two table columns

Hi lovely people,

 

I have a table loaded in Power BI with many columns, of which two are columns with abbreviations of country name. Let's call these columns 'Country A' and 'Country B', and the table containing these columns 'Countries'. For most rows, the country in the 'Country A' column is the same as the country in the 'Country B' column, but for some rows they are different. You can assume that the countries in both columns are consistently named, i.e. France is abbreviated FR and Italy is abbreviated IT is both columns.

 

I would now like to create a matrix where the columns represent the countries in the Country A column and the rows represent the countries in the Country B column, and each value in the matrix is supposed to be the number of rows with that combination of countries.

 

For example, for the Countries table:

Row No.Country ACountry B
1USIT
2FRFR
3ITFR
4FRUS
5FRUS

I would like to get the matrix:

 

Country AFRITUS
Country B   
FR110
IT001
US200

 

because on 1 row country A is equal to US and country B is IT, and on 2 rows country A is equal to FR and country B is equal two US and so on.

 

The table (loaded from an Excel sheet) is in fact much larger, but I hope that you understand my issue here. I suppose this problem can be solved using DAX in some way, but I am unsure how.

 

I would be very thankful if anyone could help me out with this. Many thanks in advance!

 

Kind regards,

Bertan

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

First create a dimension table as below:

Table 2 = DISTINCT(UNION(VALUES('Table'[Country A]),VALUES('Table'[Country B])))

Then create a measure as below:

Measure = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Country A]=MAX('Table 2'[Country A])))+0

And you will see:

Screenshot 2020-10-23 152600.png

For the related .pbix ,pls see attached.

 

Best Regards,
Kelly

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

View solution in original post

2 REPLIES 2
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

First create a dimension table as below:

Table 2 = DISTINCT(UNION(VALUES('Table'[Country A]),VALUES('Table'[Country B])))

Then create a measure as below:

Measure = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Country A]=MAX('Table 2'[Country A])))+0

And you will see:

Screenshot 2020-10-23 152600.png

For the related .pbix ,pls see attached.

 

Best Regards,
Kelly

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

Anonymous
Not applicable

The matrix visual is similar to a table. A table supports two dimensions and the data is flat, meaning duplicate values are displayed and not aggregated. A matrix makes it easier to display data meaningfully across multiple dimensions -- it supports a stepped layout. The matrix automatically aggregates the data and enables drill down.

You can create matrix visuals in Power BI Desktop reports and cross-highlight elements within the matrix with other visuals on that report page. For example, you can select rows, columns, and even individual cells and cross-highlight. Also, individual cells and multiple cell selections can be copied and pasted into other applications.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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