This is a common issue in Power Query! The problem is likely due to one of these reasons:
- Data Type Issue: The Salary column might be recognized as text instead of a number
- Null/Blank Values: Some salary cells might be empty or contain null values
- Text Values: The salary column might contain text like "error", "None", or other non-numeric values
Here are the solutions:
Solution 1: Check and Change Data Type First
Before creating the custom column:
- Select the Salary column
- Go to Transform tab
- Click Data Type and select Whole Number or Decimal Number
- If you get errors after changing the data type, those cells contain non-numeric values
Solution 2: Modified Formula to Handle Nulls and Errors
Use this more robust formula:
if [Salary] = null then "Junior"
else if Number.From([Salary]) > 40000 then "Senior"
else "Junior"
Solution 3: Handle Text Values and Errors
If your salary column contains text values like "error" or "None":
let
SalaryValue = try Number.From([Salary]) otherwise 0
in
if SalaryValue > 40000 then "Senior" else "Junior"
Solution 4: Most Comprehensive Formula
This handles all edge cases:
if [Salary] = null or [Salary] = "" or [Salary] = "None" then "Junior"
else if Text.Lower(Text.From([Salary])) = "error" then "Junior"
else
let
NumericSalary = try Number.From([Salary]) otherwise 0
in
if NumericSalary > 40000 then "Senior" else "Junior"
Step-by-Step Implementation:
-
First, clean the Salary column:
- Select the Salary column
- Go to Transform → Replace Values
- Replace "error" with 0
- Replace "None" with 0
- Replace any blank values with 0
-
Change Data Type:
- Select the Salary column
- Transform → Data Type → Whole Number
-
Then create the Custom Column:
- Add Column → Custom Column
- Name:
Seniority
- Formula:
if [Salary] > 40000 then "Senior" else "Junior"
Alternative: Using Conditional Column (GUI Method)
Instead of writing a formula, you can use the GUI:
- Go to Add Column → Conditional Column
- New column name:
Seniority
- Set conditions:
- If [Salary] is greater than 40000, then "Senior"
- Else "Junior"
This GUI method automatically handles data type conversions better.
Try these solutions and let me know which one works for your specific dataset!