Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
95Bigbluetoy
Helper I
Helper I

IF Statement help with multiple variables

I have a data set that includes columns for employee names and job titles. I have created an IF statement so that if a job title equals a certain title, it will show with a certain value in my new column. Example of this IF statement: IF([TITLE]="PROJECT EXECUTIVE", "50", IF([TITLE]="Assistant Project Manager", "25")). Now i need help editing this statement so that if the a person's name is "John Doe" whose TITLE is "Project Executive" it will show a value of 65 or if the persons name is "Jane Doe" who is also a "Project Executive" it will show 40, but all others with a Title of "Project Executive" will show a value of 50.

 

this is what my out put should show:

 

Capture.JPG

 

 

 

 

Not sure how to edit my IF statement to accomplish this. any help is greatly appreciated.

1 ACCEPTED SOLUTION

@95Bigbluetoy -

I started with the dataset below. Because I edited the file it reordered the columns.

bi2.png

[Value] is a Calculated Column. 

 

Adding [RateType] is just a suggestion. You can accomplish what you asked (not adding a helper column) by doing:

Value = 
SWITCH(
    TRUE(),
    'Table'[Name] = "John Doe" && 'Table'[Title] = "Project Executive", 65,
    'Table'[Name] = "Jane Doe" && 'Table'[Title] = "Project Executive", 45,
    'Table'[Title] = "Project Executive", 50,
    25
)

 

 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



View solution in original post

8 REPLIES 8
Greg_Deckler
Super User
Super User

First, use a SWITCH(TRUE()...) statement instead of nested IF statements. Far cleaner, more readable and easier to modify. Second, use the logical operators && (AND) and || (OR) to combine multiple criteria.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

thanks for the reply. Rather new to Power BI so trying to learn how to accomplish various tasks. I just replied to another user who suggested somewhat the same as you, but he had the same value for both John and Jane Doe. I need to have it so that John has a value of 65, Jane a value of 40 and all other PE's a value of 50. Not sure how to accomplish this with the info you provided.

 

thanks for your input.

ChrisMendoza
Resident Rockstar
Resident Rockstar

@95Bigbluetoy -

Edit: Same idea after I re-read your requirement

I would probably just add a helper flag column to your dataset instead of hard-coding Name values.

bi1.png

 

Value = 
SWITCH(
    TRUE(),
    'Table'[RateType] = 1 && 'Table'[Title] = "Project Executive", 65,
    'Table'[RateType] = 2 && 'Table'[Title] = "Project Executive", 45,
    'Table'[Title] = "Project Executive", 50,
    25
)

 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Not sure i undestand. it looks like you are creating two new columns (Value and Rate Type). what is the 25 after the 50,? I also have about 15 other job titles that i currently have in my IF statement as well. 

 

is there not a way to have conditions on the If statement to say that if the Title equals PE then 50 unless name equals John Doe, then 65 or if name equals Jane Doe then 40?

 

have to go into a meeting so will not be able to reply for a bit. thanks again for all your help.

@95Bigbluetoy -

I started with the dataset below. Because I edited the file it reordered the columns.

bi2.png

[Value] is a Calculated Column. 

 

Adding [RateType] is just a suggestion. You can accomplish what you asked (not adding a helper column) by doing:

Value = 
SWITCH(
    TRUE(),
    'Table'[Name] = "John Doe" && 'Table'[Title] = "Project Executive", 65,
    'Table'[Name] = "Jane Doe" && 'Table'[Title] = "Project Executive", 45,
    'Table'[Title] = "Project Executive", 50,
    25
)

 

 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



i would be able to add all my other job titles as well in this scenario and therefore would do away with my IF statement, correct?

Thanks for all the help. Using the examples, i was able to create the Switch statement and edit for my various titles. it worked great. 

 

Can't thank everyone enough for the help.

Thanks for the reply. I am rather new to Power Bi so trying to learn DAX. can be a bit confusing. Based on your reply, you have the same value for John and Jane Doe. In my original post, Jane Doe has a different value from John and from the other PE's. In my current dataset, my IF statement has multiple nested IF statements due to numerous job titles. This works great, until today when my boss emailed me with changes for just a few users. Previously all users with same job title has same value. now i need John Doe to have one value (65),  Jane Doe to have a value of 40 and all other PE's to have a value of 50.

 

thanks for your help.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.