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 Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Top Solution Authors
Top Kudoed Authors