Do you know the difference between calculated columns and measures in Power BI?
In this article, you’ll learn what calculated columns and measures are, how they work, and when to use them.
You’ll also get some tips and best practices for choosing between them.
https://www.selectdistinct.co.uk/2023/11/21/calculated-columns-and-measures-in-power-bi/
#powerBI #measures #calculatedcolumns
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Calculated Columns and Measures in Power BI.pptx
1. Power BI Tips
and Timesavers
Calculated Columns
And
Measures in Power BI
2. A guide to understanding the differences between calculated columns and
measures in DAX for Power BI
3. What is a calculated column?
A calculated column is a static value added to a table, calculated row by row when you load
the data.
What is a measure?
A measure is a dynamic value that changes based on what you’re looking at in a report,
calculated dynamically within the filter context of a visual
4. We will use a Gross Profit Example
We start by loading some sample sales data
5. How to create a calculated column
The first thing we will do is to calculate the Gross Profit for each row in this table
In the table view, select New Column from the Ribbon
6. How to create a calculated column
In the formula bar we type
Gross Profit = [Sales Value]-[Cost of Sales]
This adds a new column, which calculates the gross profit by subtracting the cost of sales from the sales value
When we press enter the column is added to the table, and it is calculated for each row of data in that table
We also create a Gross Profit Margin calculated column
7. Benefits & Limitations
Benefits of Calculated Columns in Power BI
One of the most obvious benefits of creating a calculated column in a table is that is easily visible and can be quickly
understood.
It is calculated once the data refreshes and is not affected by any other filters, effectively it is a static column. This means
that it can be used as a filter. In our example we could use a slicer to only show products that have a margin lower than
60%
Limitations of Calculated Columns in Power BI
Potentially the biggest draw back of calculated columns is that they must be calculated in full before the data table can be
used. This is usually not a problem if the data tables are small, but if you import a very large data table, then have complex
calculations running down a number of columns you will see a performance impact.
In that case it is often better to perform the calculation further back in the data transformation
8. How to create a measure
We want to create a measure that can calculate the overall gross profit margin, even if the report is filtered
To create the measure, go to the Table View, and click New Measure on the ribbon
Then copy and paste this DAX code
Gross Profit Margin (Measure) = sum(Sheet1[Gross Profit]) / sum(Sheet1[Sales Value])
When you press enter, the measure is created. But unlike the calculated column, it does not appear in the table view
9. Benefits of Measures in Power BI
Measures are only calculated where used and are only calculated in the context of the face value of the report, this way
they respond to filters and slicers
Limitations of Measures in Power BI
Measures can be more difficult to debug as they are more difficult to understand than a calculated column. But it can be
made simpler to understand by creating separate measures for elements of a complex calculation. For example in this
example we could create a measure for the sum of gross profit (the numerator) and check that. And we could also create a
measure for the sum of the Sales (the denominator) and check that. Out gross profit measure could then just be the
Numerator / the Denominator allowing us to debug the components separately
10. On the report view, drag a table to the canvas
Then add product, Sales Value, Cost of Sales and the calculated column for Gross Profit to the table
But, if we add the Gross profit percentage that we created as a calculated column to the table we get a problem, the
default summarisation options cannot calculate the true gross profit
Using calculated columns and
measures in reports
11. Although this initially looks correct, especially at the product row level, but the grand total is not correct
The correct answer should be 1290 divided by 2110, which equals 61.14%
The measure correctly calculates the Gross Profit percentage on the overall values and all rows in the report
Use the measure to show the gross
profit margin
12. We can use the calculated column values to filter the data for rows with a lower margin
Please note you cannot use a measure value in a slicer because you need to see the individual rows
Use the Calculated Column values if
you need to filter
13. We have explained the key differences between calculated columns and
measures in Power BI,
With examples of why you will need to use both and some of the
common errors that we see
14. For more Tips, Tricks and
Timesavers, visit our website
Business Analytics Blog – Select Distinct
Credit: simon.harrison@selectdistinct.co.uk