Open In App

Power BI – How to Add Conditional Columns?

Last Updated : 16 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Microsoft Power BI is a software program for Interactive Data Visualization with a strong emphasis on Business Intelligence. Power BI is a collection of software services, programs, and links that combine to turn unrelated data from various sources into coherent, aesthetically pleasing, and interactive insights. With Power BI Desktop, you can connect to the world of data, create foundational reports that are appealing, and share your work with others so they can build on it and advance your business intelligence initiatives.

Users can import and reshape data from a number of Microsoft applications, including Excel, Power BI, Analysis Services, Data verse, and others using Power Query, data connectivity, and data preparation tool. You can use Power Query in Power Query Editor to generate new columns whose values depend on one or more criteria that have been applied to existing columns in your table. 

How to seek Power Query Editor?

The Data Table used in the article has been formed from the Dataset of a Library Supplies company. Below is the screenshot of the dataset as well.

dataset

 

If you are witnessing the below-shown interface of the Power BI Desktop then you need to open the Power Query Editor window.

Power-BI-Desktop

 

Go to the Transform data Tab and select Transform data.

Transform-Data

 

A new Power Query Editor window would be displayed, where you can Add Upload the dataset by selecting New Source.

Power-Query-Editor

 

Data Table will be created in Power Query Editor as follows-

Data-Table

 

Adding a Conditional Column

On the Add column tab, in the General group, there is Conditional column command.

Conditional-column

 

Here, we are targeting the “Unit Price (INR/Unit)” column from the Data Table to create a conditional column “Display Price”. The condition is, if the Unit Price is less than or equal to 100, we will set the Unit Price as 150 else the original price would be unchanged, and all the changed or unchanged values would be inserted into the “Display Price” column respectively.

conditional-column-query

 

The output of the query will add the conditional column.

Added-conditional-column

 

Adding a Column by Incorporating Multiple Conditions

Now let’s add another conditional column named “Final Price”, that will contain the “Unit Price (INR/Unit)” column value, if it is less than or equal to 200, set it to 500. Else if it is greater than or equal to 500, Store the Unit Price. However, the figure from the “Total Price (INR)” column will be the Output if none of the earlier tests returned a positive result.

Multiple-conditions

 

The output of the query will add the conditional column.

Added-multiple-conditional-column

 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads