Introduction to Measures
- 04:38
An introduction to measures.
Transcript
Introduction to measures A measure is a formula but unlike a calculated column, the formula is not calculated for each row in the table instead a measure is a single value which is a result of a calculation performed on the entire column.
To perform a calculation on a column of values, you must start by using an aggregate function such as a sum or average or min or max. An aggregate will always have a numeric value as an answer.
Sometimes this is all you need, sometimes you will take that answer and then do something else with it.
Because they are not done on a row by row basis, measures are not stored in the table alongside the other columns or fields, they are stored in the report and add to the visuals as and when they are needed.
There are two types of measures in Power BI implicit and explicit. An implicit measure is easy to use and requires no formula writing. It's available on the visualizations pane and can be applied to any field.
An explicit measure requires a formula to be written it will require an aggregate function such as sum or average and often then uses other DAX functions to perform further calculations on the result.
When we use a numeric field in any visual it defaults to sum this is an implicit measure its performing an aggregate function on the entire column.
Sometimes however, we don't want it to sum, so for example, it wouldn't make sense to sum all the ages in a column. We would probably want to see the average age instead. An implicit measure can easily be changed by using the drop-down list on the visualization's pane.
However, although this is very easy to do if we are regularly using the same aggregate on lots of visuals. It might be more efficient in the long run if we create a measure to do that for us instead an explicit measure.
The explicit measure will appear in the field list alongside the other regular fields or calculated columns and can be used on as many visuals as we want without having to change the type of calculation each time on the visualization's pane.
Let's do a workout and see how to create some measures in Power BI.
So I'm just going to use Get Data to get an Excel workbook module 6 lesson 2 workout.
And from there, I'll select the transactions worksheet and load that into my report.
So the first thing I'm going to do is create a visual just going to create a card visual here, so I'll click on card and I'll use a field from my tables, so I have a list of transactions here and I have for each transaction the customer details including their age. So when I select the age field, it's numeric, by default I get a calculation but it's summing up all the edges for all my customers. So that really doesn't make sense, I want to change that to a different type of calculation. This is my implicit measure, I'm just clicking here on the arrow beside the field name and changing it to the type of calculation I want so if I change it there to average that's it done and I now I have an implicit measure.
Now, I could leave it at that, but if I'm going to find the average age in lots of different visuals, then I might want to create my own explicit measure.
So to do that, I just click on the transactions table here over at the right.
And I'm going to click on new measure on the tables tools ribbon.
I'll get a formula bar like any calculation and I have to give my measure a name, so I'm going to call it average age equals to and then I'll put in the formula and the formula uses an aggregate function called average and in a set of brackets. I just need to supply it with the field that I want to calculate the average for, so I want the average of the age field, so I'll just click on that and close my brackets, press return and my measure will now perform that calculation on the entire column sits here in my list of fields and I can use that now in my visuals instead. I'll just click on to the canvas, create a card, and now I'll use the average age instead of the normal age field and right away I have my results.