Sunday, December 10, 2017

How to Add a Custom Column to a Table in Power BI

What is Custom Column and How to Add it to a Table in Power BI
A Custom Column is a new Column that we add to a Table based on the Custom Expression, build using the Existing Columns.

The Custom Column is similar to the Conditional Column. The main difference between them is , a Conditional Column will be created using only using the IF Else Conditions with Logical Operators. but a Custom Column can be created using different Custom formulas, as well as with IF  Else Conditions.

------------------------------------------------------------------
Scenario 1 : 
Suppose we have a Sales Table where we want to create a Custom Column called "Discount" which should be Calculated as 2% of Gross_Sales .


We can do this by the following way..

1) Go to Home > Edit Queries


2) Next Go to Query Editor > Add Column > Custom Column
Select your Table and then click on Custom Column


3) Next define the Custom formula or expression for Custom Column
Formula :
Discount = [Gross_Sales]*(0.02)


Next say OK. Now we can see a new Custom Column "Discount" added to the Table.


Finally Save and Close the Query Editor then Refresh the Data. A New Column will be available now in the Table.

------------------------------------------------------------------
Scenario 2 : 

Suppose we have an Employee Table where we want to create a Custom Colum called "New_Job_Role" which should be Calculated based on the existing Column "Job_Tiltle"

based on the below logic :
IF [Job_Title]="Business Analyst" then "Data Analyst"
Else IF [Job_Title]="Business Manager" then "Analytics Manager"
Else [Job_Title]

The Employee Tables is as follows...

Now from Query Editor > Add Column tab , select the "Custom Column" and define the logic as follows..
Formula :
=if[Job_Title]="Business Analyst" then "Data Analyst"
else if[Job_Title]="Business Manager" then "Analytics Manager" else [Job_Title]


Next say OK. Now we will see a new Column has been added as "New_Job_Role"

Finally Save and Close the Query Editor then Refresh the Data. A New Column will be available now in the Table.

Important Note :
Please write the if  then else formula in the lower case to avoid the following error.
Expression error : The name 'IF' wasn't recognized. Make sure it's spelled correctly.

-------------------------------------------------------------------------------------------------------- 
Thanks, TAMATAM ; Business Intelligence & Analytics Professional 
--------------------------------------------------------------------------------------------------------

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.