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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Cyrilbrd
Helper IV
Helper IV

IF statement

Good day,

Given the following 

LocationTypeExpected result
shop1OSecom
shop1SSshop1
shop1ESemp
shop2OSecom
shop2SSshop2
shop3SSshop3
shop4OSecom

 

I tried Add Column Custom Column but can't use a nested IF statement as it returns Expression Error  The name 'IF' wasn't recognized. Make sure it's spelled correctly.
I tried to use IF THEN ELSE but I am not sure about the syntax.
Thanks for the heads-up.

 

1 ACCEPTED SOLUTION

Hi @Cyrilbrd ,

Text.Upper() function is used to convert all characters inside Type column to uppercase. If there is mixed case or lowercase values in the type column in the field, such as eS or es, it can avoid the return value of false when your condition is set to [Type]="ES"...

yingyinr_0-1636097036461.png

In addition to using an IF statement just as suggested by @mussaenda and @Jihwan_Kim to get the result you want, you can also create a calculated column by using a SWITCH statement to get it.

Column = SWITCH ( 'Table'[Type], "ES", "emp", "OS", "ecom", [Location] )

yingyinr_1-1636097248301.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Cyrilbrd
Helper IV
Helper IV

Thank you to both for clarifying the syntax of IF THEN ELSE.

@mussaenda why did you use Text.Upper(), does it mean that this IF version is case sensitive?

Hi @Cyrilbrd ,

 

Are you able to solve your issue?

 

Hi @Cyrilbrd ,

Text.Upper() function is used to convert all characters inside Type column to uppercase. If there is mixed case or lowercase values in the type column in the field, such as eS or es, it can avoid the return value of false when your condition is set to [Type]="ES"...

yingyinr_0-1636097036461.png

In addition to using an IF statement just as suggested by @mussaenda and @Jihwan_Kim to get the result you want, you can also create a calculated column by using a SWITCH statement to get it.

Column = SWITCH ( 'Table'[Type], "ES", "emp", "OS", "ecom", [Location] )

yingyinr_1-1636097248301.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Jihwan_Kim
Super User
Super User

Picture3.png

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


mussaenda
Super User
Super User

Hi @Cyrilbrd ,

 

Are you trying with DAX?

IF(
UPPER([Type]) = "OS",
"ecom",

IF(
UPPER([Type]) = "ES",
"emp",

IF(
UPPER([Type]) = "SS",
[Location],

[Location]
)
)
)

 

In Power Query

if Text.Upper([Type]) = "OS"
then "ecom"
else

if Text.Upper([Type]) = "ES"
then "emp"
else

if Text.Upper([Type]) = "SS"
then [Location]
else

[Location]

 

Assuming you have no null values on both columns used on the statement.

 

Hope this helps

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.