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.

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.

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.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.