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.
Good day,
Given the following
Location | Type | Expected result |
shop1 | OS | ecom |
shop1 | SS | shop1 |
shop1 | ES | emp |
shop2 | OS | ecom |
shop2 | SS | shop2 |
shop3 | SS | shop3 |
shop4 | OS | ecom |
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.
Solved! Go to 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"...
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] )
Best Regards
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 ,
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"...
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] )
Best Regards
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.
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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
100 | |
88 | |
69 | |
61 |
User | Count |
---|---|
151 | |
120 | |
103 | |
87 | |
68 |