DAX (Data Analysis Expressions) is a powerful formula language used in Power BI for creating calculated columns and measures. Here's how you can create them:
Calculated
Columns:
Calculated columns are computed row by
row in a table. They can be used for tasks like concatenating strings,
performing mathematical operations, or applying logical conditions on existing
columns.
To create a calculated column:
- Navigate to Data View:
- In Power BI Desktop, click on the "Data" view.
- Select Table:
- Select the table for which you want to create the calculated
column.
- Click on "New Column":
- In the "Modeling" tab, click on "New Column".
- Write DAX Expression:
- Write your DAX expression in the formula bar.
- For example, let's say you want to create a calculated column
"TotalMarks" in the "Students" table which sums up
the marks of different subjects:
TotalMarks = [Math] + [Science]
+ [English]
Measures:
Measures are calculations performed at
the aggregate level, typically over an entire table or a filtered set of data.
They are dynamic and respond to changes in filters and slicers.
To create a measure:
- Navigate to Report View:
- Click on the "Report" view.
- Click on "New Measure":
- In the "Modeling" tab, click on "New Measure".
- Write DAX Expression:
- Write your DAX expression in the formula bar.
- For example, let's say you want to create a measure
"AverageGrade" which calculates the average grade of students:
AverageGrade
= AVERAGE(Students[Grade])
- Drag and drop the newly created measure into your visualizations.
Example:
Let's say we have a table named
"Sales" with columns "Quantity" and
"PricePerUnit". We want to create a calculated column for
"TotalPrice" and a measure for "TotalSales".
Calculated Column:
TotalPrice =
Sales[Quantity] * Sales[PricePerUnit]
Measure:
TotalSales = SUM(Sales[TotalPrice])
Once
created, you can use these calculated columns and measures in your
visualizations and reports to analyze your data effectively.
Comments
Post a Comment