Adding a Custom Column in Power BI
To add a custom column in Power BI, you can follow these steps:
- Open Power BI and load the desired dataset into your report.
- In the “Fields” pane on the right side of the screen, find the table you want to add the custom column to.
- Right-click on the table name and select “Edit Queries” to open the Power Query Editor.
- In the Power Query Editor, select the column that you want to base your custom column on.
- Go to the “Add Column” tab in the ribbon and click on “Custom Column”.
- A formula bar will appear, where you can define your custom column formula.
- Enter the desired formula in the formula bar, using the M language syntax. For example, if you want to concatenate two columns together, you can use the following formula:
Table.Column1 & Table.Column2
- Press Enter to apply the formula and create the custom column.
- Click on the “Close & Apply” button in the Power Query Editor to save your changes and return to the report view.
Here’s an example to illustrate the process:
Let’s say you have a table in Power BI called “Sales Data” with columns “Product” and “Quantity”. You want to add a custom column that calculates the total sales for each product by multiplying the quantity with the respective price.
- Load the “Sales Data” table into your report.
- Open the Power Query Editor for the “Sales Data” table.
- Select the “Quantity” column.
- Go to the “Add Column” tab and click on “Custom Column”.
- In the formula bar, enter the following formula:
Sales Data[Quantity] * Sales Data[Price]
- Press Enter to create the custom column.
- Close the Power Query Editor and return to the report view.
Now, you should have a new custom column called “Total Sales” in your “Sales Data” table, which displays the calculated total sales for each product based on the quantity and price columns.