cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
elmosfire
Frequent Visitor

IF Statement - New Column

I am new to Power BI and I am struggling with "if" and "and'.   I have a column with department numbers and a column with agencies.  There are some agencies that need to be realigned based on there department number.  I want to create a new column with the correct alignment based on department number

 

if (Department Number] >=3000 and [Department Number] <=3999)
    and ([Agency] = "Train" or "Office" then "Bus")
    else [Agency]

 

I get a Token RightParen Expected.....Error highlights "then".

 

Any help would be greatly appreciated

1 ACCEPTED SOLUTION
TomMartens
Super User II
Super User II

Hey,

 

I guess if you adjust your M statement this way:

f (Department Number] >=3000 and [Department Number] <=3999)
    and ([Agency] = "Train" or [Agency] = "Office") then "Bus"
    else [Agency]

the error will disappear.

 

Regards,

Tom

 

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

2 REPLIES 2
TomMartens
Super User II
Super User II

Hey,

 

I guess if you adjust your M statement this way:

f (Department Number] >=3000 and [Department Number] <=3999)
    and ([Agency] = "Train" or [Agency] = "Office") then "Bus"
    else [Agency]

the error will disappear.

 

Regards,

Tom

 

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

Tom

 

That worked like a charm.

 

Thanks a million...much appreciated.

 

I was about to scrap this assignment.

Helpful resources

Announcements
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Get Ready for Power BI Dev Camp

Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.

Get Ready for Power BI Dev Camp

Power BI Dev Camp - September 30th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Top Solution Authors