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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
PCarson00
Frequent Visitor

IF conditions for filtering in Power Query

I have a set of data I want to filter in one column but not sure how to go about this. Here is my attempt at the explanation

 

IF text begins with "L01" or "L04"

then

remove first 3 characters

 

Else

Remove first character only

 

Is this possible to write in power query?

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

pls try this

 

if Text.Start([DATA],3) ="L01" or Text.Start([DATA],3) ="L04" then Text.RemoveRange([DATA],0,3) else Text.RemoveRange([DATA],0,1)

or========
if Text.StartsWith([DATA],"L01") or Text.StartsWith([DATA],"L04") then Text.RemoveRange([DATA],0,3) else Text.RemoveRange([DATA],0,1)

 

Screenshot_6.png

View solution in original post

4 REPLIES 4
Ahmedx
Super User
Super User

pls try this

 

if Text.Start([DATA],3) ="L01" or Text.Start([DATA],3) ="L04" then Text.RemoveRange([DATA],0,3) else Text.RemoveRange([DATA],0,1)

or========
if Text.StartsWith([DATA],"L01") or Text.StartsWith([DATA],"L04") then Text.RemoveRange([DATA],0,3) else Text.RemoveRange([DATA],0,1)

 

Screenshot_6.png

tackytechtom
Super User
Super User

Hi @PCarson00 ,

 

How about this:

tackytechtom_1-1701181411658.png


I created a new column with your requirement and the following code in M:
if Text.StartsWith([Column], "L01") or Text.StartsWith([Column], "L04") then Text.RemoveRange([Column], 0, 3 ) else Text.RemoveRange([Column], 0, 1 )

 

Let me know if this solves your quest 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Thanks Tom. On my end its not working - getting an error 'then' expected. I notice the or command is not blue?

 

PCarson00_0-1701193574358.png

 

Hi @PCarson00 ,

 

This is probably because there was some other stuff ("Table.AddColumn..., each") in the custom column formula box. My screenshot was probably misleading 🙂 

Here how it's supposed to look like:

tackytechtom_0-1701198095554.png

 

Happy you found a solution anyway! 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors