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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

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
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.