Power BI Matrix and the concept of custom measures are two important features that help users analyze and present the data. The matrix visual in Power BI helps the user to summarize data across multiple dimensions, while DAX in Power BI allows users to create custom formulas called measures. In this blog, let’s explore the matrix table and the creation of a custom measure in a matrix.
Table of Contents:
What is a Matrix in Power BI?
A Power BI Matrix is a data visualization tool that helps users display data in a grid format. The matrix table supports hierarchical data and can aggregate data at different levels. This makes it ideal for summarizing large datasets and comparing information across multiple dimensions.
What is the Use of the Matrix Table in Power BI?
The matrix Table is useful for various reasons:
- The Matrix Table displays multi-dimensional data such as sales by region and product.
- It helps in performing operations like sums, averages, and counts.
- It allows the user to look into specific information by expanding rows and columns.
Difference Between Matrix and Other Kinds of Tables in Power BI
Feature | Matrix | Table | Card |
Structure | Matrix has a Hierarchical structure with support for grouping. | The table has a Flat structure and displays only raw data. | The card is a Single value, and it is like a KPI and doesn’t support grouping. |
Aggregation | Matrix supports aggregations like sum and average. | The table displays data without aggregation. | The card is a single aggregated value. |
Expand/Collapse | Matrix allows the expansion/Collapse of data. | The table can not expand and collapse. | The card can not expand and collapse, as it is one key metric. |
Use Case | It helps in analyzing multidimensional data. | It helps in displaying raw data. | It helps in displaying a single value. |
What is Custom Measure in Power BI?
A custom measure is a DAX formula used to calculate a value based on the context of a report. It allows users to implement advanced logic, use conditional logic, and create custom calculations for visuals.
Steps to Create a Custom Measure in Power BI
We will be using a dataset that contains sales data with Amount and weight, and calculate the Weighted Average Sales.
Step 1: Load the Data
Open the Power BI desktop and load your dataset.
This is how the data looks after loading it in Power BI.
Step 2: Create New Measure
Click on the New Measure in the Modelling tab. This will open a formula bar where you can write your custom DAX formula.
After clicking on New Measure, a formula bar will open in which you need to write your custom DAX formula. We need to calculate the Weighted Average Sales
WeightedAverageSales =
SUMX(Sales, Sales[Amount] * Sales[Weight]) / SUM(Sales[Weight])
Write this DAX expression into the Formula Bar
Explanation:
- SUMX is the function that iterates over the Sales table.
- Sales[Amount]*Sales[Weight] multiplies the Amount by weight for each row in the table.
- SUM(Sales[Weight]) gives the sum of all weights.
Step 4: Apply the Measure to the Matrix Visual
Select Matrix visual in the visualizations pane and drag the Product field into the Rows section and WeightedAverageSales(new measure) into the Values section.
This is how the Visualization Panel looks, and as you can see, Product is dragged into the Rows section, and the WeightedAverageSales is dragged into the Values Section.
Step 5: Resulting Visualization
Explanation: Here, this visualization is called a matrix table, which shows the average sales of each product in Power BI.
Common Pitfalls and How to Avoid Them
1. Overcomplicating DAX formulas
When working with large datasets, writing complicated DAX formulas reduces performance and slows down report speed. Try to avoid nested functions, and keep your DAX formulas simple by using variables to store intermediate results.
2. Failing to Handle Blank and Missing Values
Handling null or missing values is very important when you are working with large data. If there are missing values, Power BI might return unexpected results. To handle these values, you can use a DAX formula like COALESCE, IFERROR, or ISBLANK.
3. Not Testing Custom Measure
After creating a custom measure, always test your calculations with different filters and slicers. Make sure that your custom formulas work as expected under various conditions.
4. Ignoring Data Relationship
In Power BI, it is very important to make sure that the data tables are related to each other. If you are working with multiple tables, then make sure that you define the correct relationship between them. If the relationship is not set, then it can result in a wrong matrix.
Best Practices
- Clear Naming: Use relevant names for your custom measures so others can easily understand the logic.
- Optimize DAX: Make sure custom DAX formulas are optimized to improve report performance.
- Use Variables in DAX: Improve readability and performance by using variables in DAX expressions.
- Limit Complex Logic: Avoid complex formulas as they can slow down your reports.
- Test Custom Measure: Ensure your DAX measure produces the expected results.
Conclusion
Power BI’s Matrix visual is combined with a custom measure, providing a powerful way to analyze and visualize complex and multi-dimensional data. By using custom DAX measures, you can create a calculation that suits your specific analysis needs. Understanding the differences between Matrix and other tables, while following best practices, will help you make interactive reports.
To learn more about Power BI and its functions, check out this Power BI Course and also explore Power BI Interview Questions prepared by industry experts.
Matrix in Power BI – FAQs
Q1. What is a matrix in Power BI?
The Matrix Table in Power BI is used to display data across multiple dimensions.
Q2. How do you format a matrix in Power BI?
You can format a matrix in Power BI by selecting the format visual icon in the visualization pane.
Q3. What is the limit of matrix columns in Power BI?
Matrix columns are limited to 100 columns.
Q4. What are Power BI metrics?
Power BI metrics are KPI(Key Performance Indicators) across specified targets.