Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
gautampruthi
Helper II
Helper II

Getting error while creating Custom Column

Hi I am trying to create a custom column based on logic if sce_udfc is not blank then use the same value in new column else use the Course Code and assign the value to new column. i have created this code but getting error as "Expression.Error: The name 'IF' wasn't recognized. Make sure it's spelled correctly."

IF(
NOT(ISBLANK([sce_udfc])),
[sce_udfc],
SWITCH(
[crs_code],
"BAS4WWCF3NWP", 5130,
"MAS3CCTH1NWP", 1700,
"MAS1EDON1NWF", 5100,
"MCS1PRPT1NWP", 1700,
"MCS1EDEC1NWP", 1700,
"RPS6EDUC1NWP", 2050,
))

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @gautampruthi 

 

Please try this for the new column

newcolumn =
IF (
    NOT ( ISBLANK ( [sce_udfc] ) ),
    [sce_udfc],
    SWITCH (
        [crs_code],
        "BAS4WWCF3NWP", "5130",
        "MAS3CCTH1NWP", "1700",
        "MAS1EDON1NWF", "5100",
        "MCS1PRPT1NWP", "1700",
        "MCS1EDEC1NWP", "1700",
        "RPS6EDUC1NWP", "2050"
    )
)

"Expressions that yield variant data-type cannot be used to define calculated columns" error occurs when it detects multiple data-types are returned in a calculated column formula. In original formula, [sce_udfc] column is of Text data type while the numbers (5130, 1700...) in SWITCH function are of whole number data type, so it leads to this error. To fix it, you can convert the numbers into Text data type by putting the numbers in double quotes. 

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

View solution in original post

4 REPLIES 4
gautampruthi
Helper II
Helper II

Hi @miTutorials Thanks for your prompt response, now i am getting error as "Expressions that yield variant data-type cannot be used to define calculated columns"

Both column is of Text Data Type

Anonymous
Not applicable

Hi @gautampruthi 

 

Please try this for the new column

newcolumn =
IF (
    NOT ( ISBLANK ( [sce_udfc] ) ),
    [sce_udfc],
    SWITCH (
        [crs_code],
        "BAS4WWCF3NWP", "5130",
        "MAS3CCTH1NWP", "1700",
        "MAS1EDON1NWF", "5100",
        "MCS1PRPT1NWP", "1700",
        "MCS1EDEC1NWP", "1700",
        "RPS6EDUC1NWP", "2050"
    )
)

"Expressions that yield variant data-type cannot be used to define calculated columns" error occurs when it detects multiple data-types are returned in a calculated column formula. In original formula, [sce_udfc] column is of Text data type while the numbers (5130, 1700...) in SWITCH function are of whole number data type, so it leads to this error. To fix it, you can convert the numbers into Text data type by putting the numbers in double quotes. 

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

Can you share sample pbix ?

miTutorials
Super User
Super User

I have checked the below and it is working, please test. Right click on the table and choose NewColumn.

 

Column = IF(
NOT(ISBLANK([Test])),
[Test],
SWITCH(
[Check],
"BAS4WWCF3NWP", 5130,
"MAS3CCTH1NWP", 1700,
"MAS1EDON1NWF", 5100,
"MCS1PRPT1NWP", 1700,
"MCS1EDEC1NWP", 1700,
"RPS6EDUC1NWP", 2050
))

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.