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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

case when or if with strings in Power Query

I am new to Power BI but have used SQL. Both M and DAX are making me feel stupid!! Thanks for letting me vent.

 

I have a column that groups students into 8 different types. I want to use an if statement or case when statement to bring that down to 4 and put the 4 new labels into a new column. I am pretty sure I need to do with in Power Query. This is what I have so far. What am I doing wrong?

 

"Trad Fleer Grad", each if [College]='ADULT' then 'Fleer'
else if [College]='GRAD' then 'Graduate'
else if left([College],1)='V' then 'Nondegree'
else 'Traditional')

 

Also, is there an "in" command, such as

if [College] in ('TRAD','5YTRD','PTTRAD') then 'Traditional'

 

 

2 ACCEPTED SOLUTIONS
wdx223_Daniel
Super User
Super User

if List.Contains({"TRAD","5YTRD","PTTRAD"},[College]) then "Traditional"

View solution in original post

mussaenda
Super User
Super User

Hi @Anonymous ,

 

I understand that in SQL, you should be using ' '.

But in Power Query, it should be " ".

 

 if

[College] = "ADULT"

then "Fleer"
else

 

if [College] = "GRAD"

then "Graduate"
else

 

if

Text.Start( [College], 1) = "V"

then "Nondegree"
else

 

"Traditional"

 

 

-----------

if

List.Contains( {"TRAD","5YTRD","PTTRAD"}, [College] )

then "Traditional"

else

 

YourConditon

 

Hope this helps

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Thank you both. I asked one question and learned a lot: about the spaces, " instead of ', List.Contains, Text.Start, and those { }. I am on a roll. 

mussaenda
Super User
Super User

Hi @Anonymous ,

 

I understand that in SQL, you should be using ' '.

But in Power Query, it should be " ".

 

 if

[College] = "ADULT"

then "Fleer"
else

 

if [College] = "GRAD"

then "Graduate"
else

 

if

Text.Start( [College], 1) = "V"

then "Nondegree"
else

 

"Traditional"

 

 

-----------

if

List.Contains( {"TRAD","5YTRD","PTTRAD"}, [College] )

then "Traditional"

else

 

YourConditon

 

Hope this helps

wdx223_Daniel
Super User
Super User

if List.Contains({"TRAD","5YTRD","PTTRAD"},[College]) then "Traditional"

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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