Open In App

How to Add a Conditional Column in Power Query in Excel?

Last Updated: 31 Jan, 2023

C

Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

We may use Power Query to generate new columns whose values depend on one or more criteria that have been applied to existing columns in your database. The condition imposed on an existing column in the data model serves as the foundation for Power BI’s conditional column. On the Add column tab, in the General category, is the Conditional column command. In this article, we are going to discuss the Conditional column in Power Query and in Power Pivot queries.

Step By Step Implementation

Step 1: Create an excel table with fields Roll No., Student name, and Marks.

creating-excel-table

 

Step 2: Select a table. Then navigate to the data tab on the top of the ribbon and select the Get Data option and then go to from other sources and choose from Table/range.

selecting-other-sources

 

Step 3: Then create a Table dialog box appear. Here select the range and check my table has headers then click on OK.

create-table-dialog-box

 

Step 4: Now as you can see the excel table is converted to a power query editor.

table-converted-into-power-query-editor

 

Step 5: Now in the power query go to the add column tab on the top of the ribbon and here select the conditional column.

selecting-conditional-column

 

Step 6: Add Conditional Column dialog box appears. Here write the new column name and then apply the if condition.

adding-conditional-column

 

Step 7: Here in the New column name we gave a column name Pass/Fail. Then in the If condition in column name selects Marks, in Operator Select is greater than, in value write 40 and in the output write Pass. Now click on Add clause.

filling-details

 

Step 8: Now in the Else If condition in column name selects Marks, in Operator Select is less than, in value write 40 and in the output write Fail and then click OK.

else-if-condition

 

Step 9: Now as you can see new column is created with Pass/Fail name. Here it shows the students whose marks are less than 40 fail and the students whose marks are more than 40 Pass.

marks-shown

 



C

News
Improve
Discuss
Do you want to advertise with us?Click here to know more

Excel - Types of Merging of Queries in Power Query

article_img
In Power Query, we have an option to Combine two tables using “Merge queries”. Merge Queries: Merge with current query with another queryMerge Queries as New: Merge with current query with another query and create New query In this article, we explore different types of merging of queries in Power Query with two tables. We will combine two years of sales data (2020 and 2021) with the key field “Cust_ID”. Implementation: Follow the below steps to implement merging of queries: Step 1: Open Power Query Editor. Step 2: Select your Query “Sales_2020”. Go to Home >> Merge Queries >> Merge Queries as New. We have six type of joins: Left Outer (all from first, matching from second)Right Outer (all from second, matching from first)Full Outer (all rows from both)Inner (Only Matching rows)Left Anti (rows only in first)Right Anti (rows only in second) Step 3: Select Second table; Select key fields “Cust_ID” in both tables; Select Left Outer (all from first, matching from second) and Press “OK”. Step 4: Above step create a new query “Merge 1” as below in your power query. Note: Sales_2021 is not a text value it is a table for each row. Step 5: Click “Sales_2021” drop down icon; M
Read More

How to Create a Relative File Path with Power Query in Excel?

article_img
In today's digital environment, sharing Excel files effectively is vital. A common issue is that Excel's Power Query uses absolute file paths, which can break when files are opened on different systems. To enhance portability and maintain data connections, it's crucial to convert these absolute paths to relative paths. This article explains how to make Excel workbooks more shareable by using Power Query to switch from absolute to relative file paths. How to Create a Relative File Path with Power Query in Excel?Why Convert Absolute Paths to Relative Paths?Problem with Absolute Path: Absolute paths can cause issues when sharing files because the path is specific to the original user's computer. Due, to this file sharing, is a big and significant issue. For example, an analyst is analyzing data in its intelligence tools source via power query from your PC, the tools work well until the files are in your PC, but stop working as soon as they are imported into the third person PC, this happens because the absolute path in the third person computer might be different, and our power query files are still searching for the old absolute path provided in my computer. To resolve this issue, on
Read More

C

Date Modifications with Power Query in Excel

A data preparation and transformation engine is Power Query. Power Query includes a Power Query Editor for implementing transformations as well as a graphical interface for obtaining data from sources. With Power Query (also referred to as Get & Transform in Excel), you may import or connect to external data and then modify that data to match your needs, for instance, by combining tables, altering the data type, or eliminating a column. When you're ready to produce charts and reports, load your query into Excel. You may periodically update the data by refreshing it. Steps to Open Power Query in Excel Step 1: First create a table in Excel. Step 2: Select the field and then navigate to the data tab on the top of the ribbon. Then select the Get data option and choose From other sources and select From Table/Range option. Step 3: Then Create Table dialog box appears. Here select the table range and then click OK. Step 4: Now you can see it converts the excel table to a power query Editor. Date modification with Power QueryAge The number of days between the specified date and the current date is determined when you choose the Age option and choose a date column. Next, you mu
Read More

Text Modifications with Power Query in Excel

article_img
In Excel, Power Query is a business intelligence tool that is used to analyze the data imported from different sources. With the help of power query, we can easily clean, transform and reshape our data as per requirement along the way of analyzing the data. In this example, we will learn about the Text Functions which can be easily used with the help of Power BI for the modification of the data. Given below are the formatting functions that can be used to create and manipulate the text values. Function Name Description Trim It is used to trim(remove) the whitespace from both ends of the text.Clean It removes the non-printable characters from the text and returns it.Merge Columns It is used to combine two or more columns into a single column using a separator.Lowercase It is used to make text lowercase.Uppercase It is used to make text uppercase.Add Prefix It is used to add prefixes to a cell or set of cells.Add Suffix It is used to add suffixes to a cell or set of cells.Capitalize Each Word It is used to change a text into proper text.Text Modifications with Power Query Step 1: Create a Database. In order to use the text operations, we will be using the following random names.  Fig
Read More

D

How to Import, Edit, Load and Consolidate Data in Excel Power Query?

article_img
Power Query is an easy and efficient way of solving simple data tasks. Most of our valuable time is frequently consumed by tedious manual procedures like cut and paste, column merging, and filtering. These operations are greatly simplified with the Power Query tool. A further advantage is that, in comparison to other BI tools, Power Query is simple to use. The Power Query user interface is straightforward. Given how much it resembles the Excel interface, many users will find it to be familiar. What is Power Query? Power Query is an application for preparing and transforming data. Using Power Query, you may perform transformations to data obtained from sources using a Power Query Editor and a graphical user interface.  We can import data from a variety of sources, clean it, convert it, and then reshape it to suit our needs using Power Query, a business intelligence tool provided by Microsoft Excel. Power Query allows us to create a query just once and reuse it later by simply refreshing it. Different Ways to Import Data to the Excel Sheet Excel allows importing data from a variety of sources. We will look at each of these in detail. While importing data, power query has several feat
Read More

How to Calculate Conditional Probability in Excel?

Conditional probability is calculating the probability of an event provided the event associated is already done. In other words, If we have to find the conditional probability of two events suppose A and B, then we are finding the probability of event A happening given that event B has already occurred. The formula of conditional probability having events A and B are as follows: P (A|B) = \frac{P(A\cap{B})}{P(B)} Steps to Calculate Conditional Probability in Excel For example, The data below represents a population of a town that uses social networking sites namely LinkedIn and Facebook. The data shows the number of people using Facebook and Using LinkedIn, the number of people using Facebook but not using LinkedIn, and so on. The total population taken is 200. Now, we need to calculate, Probability of people using Facebook. P(Use Facebook)Probability of people using Facebook and using LinkedIn. P(Use Facebook AND Use LinkedIn)The conditional probability of people using Facebook who also uses LinkedIn. P(Use Facebook| Use LinkedIn)The conditional probability of people using LinkedIn who also uses Facebook. P(Not Use LinkedIn| Use Facebook)Calculating Probability of People using
Read More

How to Apply Conditional Formatting in a Pivot Table in Excel

article_img
One of the most useful ways to customize the pivot table formatting is using Conditional Formats. Conditional formatting rules can be applied to Pivot tables just like they can be applied to normal data ranges. So by using conditional formatting, we can highlight the cells with a certain color depending on the cell's value. Conditional FormattingWhat is Pivot Table Conditional Formatting In Excel, you have the power to make your data stand out using conditional formatting. This means you can automatically highlight cells that meet certain criteria. For example, you can easily spotlight cells that have values above the average or those that fall below a specific threshold. Now, when you apply this special formatting to a Pivot table, there is an important step to remember. After you've set up your conditional formatting, make sure to tweak the settings so that even after you refresh the Pivot table, the right cells maintain their distinctive appearance. This ensures that your highlighted information remains accurate and up-to-date as your data evolves. Types of Conditional Formatting in ExcelThere are many conditional formats that we can use on our data. Some of them are given below
Read More

I

How to Apply Conditional Formatting Based On VLookup in Excel?

VLOOKUP is an Excel function to lookup data in a table organized vertically. VLOOKUP supports approximate and exact matching, and wildcards (* ?) for partial matches. Conditional Formatting Based on Vlookup: 1. Using the Vlookup formula to compare values in 2 different tables and highlighting those values which is only present in table 1 using conditional formatting. We have a Table containing old products of any grocery shop in 'Old Product' sheet and an updated table having new products in worksheet 'New'. We want to highlight rows in New table containing those items which are not in Old Product Table. Old Product Select the data from New table except the Headers. (The table in which we want to highlight rows.)Go to Home->Conditional Formatting->New Rule. In the dialog box appeared, Select the rule type - "Use a formula to determine which cells to format;";Under Edit the rule description enters the following formula: =ISNA(VLOOKUP($A2,'Old Product'!$A$1:$B$8,1,FALSE))Then click Format. Formula explanation: Inside VLOOKUP, 1st parameter is $A2 which is first name in New table.2nd parameter is Old Product Table.3rd parameter is column we want to compare which is 1 as we wan
Read More

How to use Conditional Formatting in Excel?

article_img
Microsoft Excel is a software that allows users to store or analyze the data in a proper systematic manner. It uses spreadsheets to organize numbers and data with formulas and functions. MS Excel has a collection of columns and rows that form a table. Generally, alphabetical letters are assigned to columns, and numbers are usually assigned to rows. The point where a column and a row meet is called a cell. Conditional formatting is a feature in Excel that allows you to format/highlight few particular cells that meet the condition specified or selected by you. You can find it in the home tab under the Styles group. Steps to use Conditional Formatting: Step 1: Insert the data/values in the spreadsheet. Step 2: Select the range of cells. Step 3: Click on the Conditional formatting in the Home tab. Step 4: Select any predefined condition or create your own condition(for this select New Rule). For example, we need to: Highlight marks which are more than 70.Highlight marks which are between 50 and 80.Highlight marks that are below average.Set icons on the marks.Show data bars on the marks.Steps to highlight marks that are more than 70 Step 1: Insert the data in the spreadsheet, we enter t
Read More

Conditional Formatting in Excel: Basic to Advanced Guide

article_img
How to Do Conditional Formatting in Excel: Quick StepsSelect the Cells to FormatGo to the Home Tab >> Click on Conditional FormattingChoose a Formatting RuleSet Your Condition and Formatting StyleClick OKEver stared at a spreadsheet full of numbers and wished it could show you what’s important instead of making you guess? Conditional formatting in Excel does exactly that—it turns raw data into visual insights with just a few clicks. Whether you’re tracking sales trends, monitoring project deadlines, or analyzing survey results, this feature helps you spot patterns, highlight outliers, and make data-driven decisions faster.This guide covers everything from basic conditional formatting to advanced conditional formatting techniques, including how to highlight cells based on values, use color scales to visualize data, and flag duplicate cells automatically. You’ll also learn to create custom rules with formulas and clean up your sheets by removing outdated formatting. How to Use Conditional Formatting in ExcelTable of ContentWhat is a Conditional Formatting in ExcelHow to Use Conditional Formatting to Highlight cells Based on Another Cell in Excel1. Highlight Cells Based on Value
Read More
three90RightbarBannerImg