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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
KaiRado
Frequent Visitor

Power Query Text.StartsWith() range of values

Hi, 

 

I would like to filter my data in the TableName table by the following condition: select data where column Code starts with V[2-9] OR M[2-9] OR contains ("MS" OR "PO"). That means that I want data where Code contains "MS" or "PO" or starts with: V2, V3, V4, M2, M3, M4, M5, and so on. 

I wrote the following:

Table.SelectRows(TableName,
each List.Contains({"MS", "PO"}, [Code]) or Text.StartsWith([Code]),....)

)

But I don't know how to finish it, so I get the result I want.

 

Do you gyus have any ideas?

Thank you very much in advance!

1 ACCEPTED SOLUTION

Hi @KaiRado ,

 

Not super nice, but this one maybe?

= Table.SelectRows ( Source, each
    ( Text.Contains ( [Code], "MS" ) ) or 
    ( Text.Contains ( [Code], "PO" ) ) or 
    ( ( Text.StartsWith ( [Code], "V" ) or Text.StartsWith ( [Code], "M" ) ) 
    and List.Contains( {"2","3","4","5","6","7","8","9"},Text.At([Code] , 1 ) ) )
)

 

/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 

View solution in original post

4 REPLIES 4
tackytechtom
Super User
Super User

Hi @KaiRado ,

 

Before:

tomfox_0-1662572331625.png

 

 

After:

tomfox_1-1662572356532.png

 

 

The code:

= Table.SelectRows ( Tablename, each 
    ( Text.Contains ( [Code], "MS" ) ) or 
    ( Text.Contains ( [Code], "PO" ) ) or 
    ( ( Text.StartsWith ( [Code], "V" ) or Text.StartsWith ( [Code], "M" ) ) and Number.FromText ( Text.At ( [Code] , 1 ) ) >= 2 ) 
) 

 

Let me know if this fixes your issue 🙂

 

/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 

Hi @tackytechtom !

 

Thank you very much for your solution. It partly worked. The thing is that I'm receiving an error: "We couldn't convert to Number...". I think the problem is that some values of the Code column on the second position contain letters or spaces (for example "MY" or "M J"). 

 

Thank you for your time!

Hi @KaiRado ,

 

Not super nice, but this one maybe?

= Table.SelectRows ( Source, each
    ( Text.Contains ( [Code], "MS" ) ) or 
    ( Text.Contains ( [Code], "PO" ) ) or 
    ( ( Text.StartsWith ( [Code], "V" ) or Text.StartsWith ( [Code], "M" ) ) 
    and List.Contains( {"2","3","4","5","6","7","8","9"},Text.At([Code] , 1 ) ) )
)

 

/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 

Hi @tackytechtom ,

 

that worked! Thank you very much!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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