Adding Custom Columns Use of IF statement

When trying to add a “Custom Column” using the following code:
= Table.AddColumn(#“Changed Type”, “Status”, each IF([Registered Credits] >= 12, “Full Time”, “Part Time”))
Power BI returns the error message:
Expression.Error: The name ‘IF’ wasn’t recognized. Make sure it’s spelled correctly.

Thank you in advance for any help with this issue.
Eduardo From Ann Arbor, Michigan.

1 Like

This should work for you, you were missing the then & the else. IF statements work the same way as they do in Excel but they have different syntax.

Table.AddColumn(#“Changed Type”, “Return”, each if [Registered Credits] >= 12 then “Full Time” else “Part Time”)

David

2 Likes

Great blog post here about this from the fantastic Rick de Groot

Mastering IF Statements in Power Query - including nested if-statements (gorilla.bi)

2 Likes

Great support @DavieJoe !

@lebtechus please know that Power Query is case sensitive, therefore keywords like: if, then and else need to be written in lowercase as illustrated in the first response by @DavieJoe

2 Likes

Ah, yes, great point about lowercase. I FORGOT that BIT :rofl:

1 Like

DavieJoe: Thank you for the reply. I will keep your advise in mind when working with Power BI. I am an old SQL programmer that loves to write statements in upper case. My query now works fine.

2 Likes

Cool, don’t worry, I come from a heavy Excel background and I have to regularly remind myself that IF statements work in the same way but with slightly different syntax.