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
emman_burgonia
Frequent Visitor

Creating a Matrix Based on the Column Values - Categorical Data

Hello, 

 

I am pretty new and Power BI and I am researching a lot but I'm having trouble creating a solution for this. I have this table in Power Query 

emman_burgonia_0-1663341921242.png

And I'm trying to produce something like this:

emman_burgonia_1-1663341973105.png

I'm looking for the COUNTIFS function but I am not sure what is its equivalent in DAX. Thanks for your help. 

 

 

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

Ok, let's take this step by step...

A) We need to unpivot the columns in Power Query. This involves

  1. Creating an index column
  2. Selecting the index column, right click and select "Unpivot other columns"
  3. Deleting the index column
  4. deleting blank rows from the value column and renaming the facilities column

Like this:

MC.gif

B) Creating dimension tables for both Facility and Value field:

  1. Select the facility colum, right click and select "Add as new query"
  2. Convert this list into a table by clicking on the "Convert to Table" in the ribbon (no aggregation)
  3. Select the column and Remove duplicates under "Remove Rows" in the ribbon
  4. Rename the field and table

Like this:

Dim.gif

Repeat the process for the "Value" field and load into the model

C) Create relationships between each field in the Dimnesion Tables and their corresponding field in the Fact table (In my example named "Facilities Table")

model.gif

 

D) Build the matrix:

        1. Create the measure to count the Values:

 

Count Value Measure = COUNT('Facilities Table'[Value])

 

       2. Build the matrix using the fields from the dimension tables: dFacility in the Rows bucket; dValue in the Columns Bucket; and add the [Count Value Measure] to the values bucket to get:

matrix.png

 

I've attached the sample PBIX file





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

1 REPLY 1
PaulDBrown
Community Champion
Community Champion

Ok, let's take this step by step...

A) We need to unpivot the columns in Power Query. This involves

  1. Creating an index column
  2. Selecting the index column, right click and select "Unpivot other columns"
  3. Deleting the index column
  4. deleting blank rows from the value column and renaming the facilities column

Like this:

MC.gif

B) Creating dimension tables for both Facility and Value field:

  1. Select the facility colum, right click and select "Add as new query"
  2. Convert this list into a table by clicking on the "Convert to Table" in the ribbon (no aggregation)
  3. Select the column and Remove duplicates under "Remove Rows" in the ribbon
  4. Rename the field and table

Like this:

Dim.gif

Repeat the process for the "Value" field and load into the model

C) Create relationships between each field in the Dimnesion Tables and their corresponding field in the Fact table (In my example named "Facilities Table")

model.gif

 

D) Build the matrix:

        1. Create the measure to count the Values:

 

Count Value Measure = COUNT('Facilities Table'[Value])

 

       2. Build the matrix using the fields from the dimension tables: dFacility in the Rows bucket; dValue in the Columns Bucket; and add the [Count Value Measure] to the values bucket to get:

matrix.png

 

I've attached the sample PBIX file





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






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.