Adding a Calculated Column in Power BI
Power BI provides the ability to create calculated columns, which are columns derived from an expression or formula based on the data in other columns of a table. These calculated columns are useful for data transformation and creating custom calculations in your Power BI reports. Here’s how you can add a calculated column in Power BI:
- Open Power BI Desktop and load your data into the Power Query Editor.
- Select the table in which you want to add the calculated column.
- Click on the “Modeling” tab at the top of the Power Query Editor.
- Click on the “New Column” button in the Calculations group.
- Enter a name for your calculated column in the formula bar.
- Write the expression or formula for your calculated column in the formula bar.
- Press Enter or click the “Check Mark” button to apply the calculated column.
For example, let’s say you have a table called “Sales” with columns for “Revenue” and “Units Sold”. You want to create a calculated column to calculate the average revenue per unit sold. Here’s how you can do it:
- Load the “Sales” table into the Power Query Editor.
- Select the “Sales” table in the tables list.
- Click on the “Modeling” tab at the top of the Power Query Editor.
- Click on the “New Column” button in the Calculations group.
- Enter “Avg Revenue per Unit Sold” as the name for the calculated column in the formula bar.
- Write the following expression in the formula bar:
=[Revenue] / [Units Sold]
- Press Enter or click the “Check Mark” button to apply the calculated column.
Once the calculated column is added, you can use it in your Power BI reports and visualizations, just like any other column in your table. The calculated column will be recalculated whenever the data in the underlying columns changes.