How to Add a Conditional Column in Power BI
Adding a conditional column in Power BI allows you to create a new column in your dataset based on certain conditions. This can be useful for categorizing data or performing calculations based on specific criteria.
Example:
Let’s say you have a sales dataset with columns for “Product Name” and “Quantity Sold.” You want to create a new column called “Product Category” based on the following conditions:
- If the quantity sold is less than 50, the product category is “Low Sales”
- If the quantity sold is between 50 and 100 (inclusive), the product category is “Medium Sales”
- If the quantity sold is greater than 100, the product category is “High Sales”
To add a conditional column in Power BI, follow these steps:
- Open your Power BI Desktop application and load your dataset.
- Go to the “Modeling” tab in the ribbon menu.
- In the “Tables” section, click on “New Column.”
- In the formula bar, enter the following formula:
[Product Category] =
IF([Quantity Sold] < 50, "Low Sales",
IF([Quantity Sold] <= 100, "Medium Sales", "High Sales"));
This formula uses the “IF” function to evaluate the conditions. If the quantity sold is less than 50, it assigns “Low Sales” to the new column. If the quantity sold is between 50 and 100, it assigns “Medium Sales.” For any quantity sold greater than 100, it assigns “High Sales.”
- Press Enter to apply the formula.
After following these steps, you should see a new column called “Product Category” in your dataset with values based on the conditions specified in the formula. This column can now be used for visualization, filtering, or further calculations.