Power BI Tutorial - Power BI Tutorial on Calculated Fields
Posted by Superadmin on August 20 2020 04:45:38

 

 

Power BI Tutorial - Power BI Tutorial on Calculated Fields

 

Sometimes, we don’t get the columns that we need to perform visualization. In these situations, we can create Power BI calculated fields that we have shown below. Within these columns, we can write simple arithmetic operations or the most powerful Power BI DAX functions.

  1. Calculated Columns
  2. Conditional Columns
  3. Calculated Measures
  4. Calculated Tables
  5. Custom Columns

Create Calculated Columns in Power BI

Microsoft Power BI allows you to create custom columns (or calculated columns) from existing columns. In this section, we show you how to create calculated columns in Power BI with example.

  

To demonstrate this Power BI calculated columns, we are going to use the SQL Data Source that we created in Connect Power BI to SQL Server article. So, refer to the same.

Create Calculated Columns in Power BI 1

How to Create Calculated Columns in Power BI

In order to create a calculated column, please click on the New Column option under the Modeling tab.  

 

Create Calculated Columns in Power BI 2

Clicking the New Column tab opens the Power BI DAX formula bar, as we shown below.

Create Calculated Columns in Power BI 3

You can rename this calculated column as per your requirement. Let me rename the column as Profit

  Create Calculated Columns in Power BI 4

For this Calculated Columns demo purpose, we select Sales Amount and Total Product Cost from Fact Internet Sales table. As you can see from the screenshot below, while I was typing, Power BI IntelliSense is showing the suggestions.

Create Calculated Columns in Power BI 5

From the screenshot below, you can see, we are calculating the Profit by removing Total Product Cost from Sales Amount. Next, by clicking the enter, a new column called profit created.

Create Calculated Columns in Power BI 6

Let me add the calculated column that we created earlier to the existing Table. Remember, this is the table that we created in the Create Table Report article.

Create Calculated Columns in Power BI 7


 

Add Conditional Column in Power BI

Power BI Conditional column generates a new column based on the condition that we specify — for example, creating an appraisal column based on employee performance, etc. Let me show you how to add a Conditional Column in Power BI with example.

  

How to add Conditional Column in Power BI

To demonstrate this Power BI Conditional Column, we are going to use the SQL table that we imported in Enter Data article.

To add a conditional column, please click the Edit Queries option under the Home tab.  

 

Add Conditional Column in Power BI 1

Clicking the Edit Queries option opens a new window called Power BI Power Query Editor. In this example, we are going to use the Sales column.

Add Conditional Column in Power BI 2

First, go to Add Column Tab. Under this tab, you can see the Conditional Column button. You can use this button to add the conditional column to this table.

  Add Conditional Column in Power BI 3

Clicking the Power BI Conditional Column button opens the following window.

Add Conditional Column in Power BI 4

We changed the Column name as Rating. Next, we selected the Column name as Sales

Add Conditional Column in Power BI 5

Next, we selected the Operator as greater than, and value as 3000. Within the Values or Output text box, either you can give the static values, or you can select the column.

Add Conditional Column in Power BI 6

We added the first Rule – If Sales is greater than 3000, then return Excellent inside the rating Column. Next, click the Add rule button to add a new rule.

Add Conditional Column in Power BI 7

As you can see from the screenshot below, we added two more rules. Remember, this is the same as the Else If Statement in SQL.

Add Conditional Column in Power BI 8

You can use the ….. button to move selected Rule to up and down, or you can delete it as well. For now, we are leaving as it is, and click the OK button

Add Conditional Column in Power BI 9

From the screenshot below, you can see the new column with the information that we specified in the conditional column. Next, hit the Close & Apply option under the Home tab to apply these changes.

Add Conditional Column in Power BI 10

Now you can see the new Power BI Conditional Column called rating under the SQL Employees table.

Add Conditional Column in Power BI 11

 

 

Create Calculated Measures in Power BI

In Microsoft Power BI, you can create a custom calculated measure (or numeric aggregated calculation) from existing columns. In this article, we show you how to create calculated measures in Power BI with example.

  

To demonstrate this Power BI calculated measures, we are going to use the Data Source that we created in Connect Power BI to SQL Server article.

Create Calculated Measures in Power BI 1

How to Create Calculated Measures in Power BI

In order to create a calculated measure, please click on the New Measure option under the Modeling tab.  

 

Create Calculated Measures in Power BI 2

Clicking the Power BI New Measure tab opens the DAX formula bar with default measures name, as we showed below.

Create Calculated Measures in Power BI 3

You can rename this calculated measure as per your requirement. Let me rename the measure as Total Sale

  Create Calculated Measures in Power BI 4

For the Power BI calculated measures demo purpose, we add the Internet Sales Amount, Reseller Sales Amount from Fact Internet Sales, and Fact Reseller Sales tables. Unlike calculated columns, you have to use the aggregated function to create a measure.

As you can see from the screenshot below, while I was typing, Power BI IntelliSense is showing the suggestions.

Create Calculated Measures in Power BI 5

By clicking the enter or any key, a new Measure called TotalSale created.

Create Calculated Measures in Power BI 6

Let me add the calculated Measure that we created earlier to a Table. Please refer Create Table Report article to understand the steps involved in creating a table

Create Calculated Measures in Power BI 7

Let me minimize the Fields tab and Visualization so that you can focus on table values.

Create Calculated Measures in Power BI 8

You can also apply filters on these calculated measures too. From the screenshot below, you can see that we selected a few areas in our Pie Chart, and the same has been reflected in the table as well.

Create Calculated Measures in Power BI 9

 

 

Create Calculated Tables in Power BI

In Power BI, you can create a custom table or calculated table from the existing table. In this article, we show you how to create calculated tables in Power BI with an example.

  

To demonstrate this Power BI Calculated Tables, we are going to use the SQL Data Source that we created in Connect Power BI to SQL Server article. So, please refer to the same.

Create Calculated Tables in Power BI 1

How to Create Calculated Tables in Power BI

In order to add the calculated table, please click on the New Table option under the Modeling tab.  

 

Create Calculated Tables in Power BI 2

It will open the Power BI DAX formula bar to write DAX expression, as we have shown in the screenshot below.

Create Calculated Tables in Power BI 3

Let me rename the default table name as Countries

  Create Calculated Tables in Power BI 4

For this Calculated Tables demo purpose, we are selecting Countries from the DimGeography table. As you can see from the screenshot below, while I was typing, Power BI IntelliSense is showing the suggestions.

Create Calculated Tables in Power BI 5

From the screenshot below, you can see, we are selecting the DISTINCT (non-duplicates or unique) countries’ names from the Countries column.

Create Calculated Tables in Power BI 6

By clicking the enter or any key for that matter will create a new table called Countries holding distinct country names.

Create Calculated Tables in Power BI 7

Let me create a Map using that calculated table that we created earlier.

Create Calculated Tables in Power BI 8

 

 

 

Create a Custom Column in Power BI

Power BI Custom column generates a new column based on the existing columns. For example, you can use this to calculate the profit or loss, etc. Let us see how to create a custom column in Power BI with an example.

  

How to create custom column in Power BI

To demonstrate this custom Column, we are going to use the Internet Sales table that we imported in Connect to SQL Data Source article.

To add or create a custom column, please click the Edit Queries option under the Home tab.  

 

Create a Custom Column in Power BI 1

Clicking the Edit Queries option opens a new window called Power Query Editor.

In this example, we are going to calculate the profit using the Total Product Sale and the Sales Amount.

  Create a Custom Column in Power BI 2

To add a custom column in the Power BI report, go to Add Column Tab. Under this tab, please click on the Custom Column button, as shown below.

Create a Custom Column in Power BI 3

Clicking the Custom Column button opens the following window.

Create a Custom Column in Power BI 4

We changed the Column name as Profit. Next, we are subtracting the total product from the sales amount.

Create a Custom Column in Power BI 5

Now you can see the new column profit

Create a Custom Column in Power BI 6

Let me rearrange columns so that you can see them side-by-side

Create a Custom Column in Power BI 7

Hit the Close & Apply option under the Power BI Home tab to apply these changes.

Create a Custom Column in Power BI 8