• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

what is the syntax for exact match in Text.Contains("LMS800", [Document])|Power Query|Excel Forum|My Online Training Hub

You are here: Home / what is the syntax for exact match in Text.Contains("LMS800", [Document])|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower Querywhat is the syntax for exact match …
sp_PrintTopic sp_TopicIcon
what is the syntax for exact match in Text.Contains("LMS800", [Document])
Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
1
March 6, 2020 - 4:49 pm
sp_Permalink sp_Print

Hi,

What is the Syntax for Text.Contains M code in Power Query

i.e.  LMS800 = LMS800,  LMS800C4 = LMS800C4

If Document =  "....................LMS800C4.........."   then return LMS800C4 exactly instead of two outputs (See my attachment)

Thank you!

sp_AnswersTopicSeeAnswer See Answer
Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4436
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
2
March 7, 2020 - 3:14 pm
sp_Permalink sp_Print

Hi Chris,

There are some suggestions here.

Mynda

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
3
March 7, 2020 - 3:45 pm
sp_Permalink sp_Print

Hi Mynda,

what they meant by "wrapping the string text in single spaces (b4 and after). Did the same with the list of lookup values.................."

thank you !

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
4
March 7, 2020 - 5:11 pm
sp_Permalink sp_Print

place a space before and after the text, however only one found don't know why ?

Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4436
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
5
March 8, 2020 - 8:14 pm
sp_Permalink sp_Print

Hmmm, because the documents that don't have 'Project' at the end don't have a space after the project code. Why don't you split the Project... off the end of the documents so they're consistent, then it may work better. See attached.

Mynda

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
6
March 9, 2020 - 1:24 am
sp_Permalink sp_Print

Hi Treacy,   in my real data source is not so "structured" meaning,  the project number can appear anywhere in a verbatim,  so there is no way to split it until so clean,  that was why I use the function match that uses Text.Contains( )

Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 608
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
7
March 9, 2020 - 10:49 pm
sp_Permalink sp_Print

You could add a query that calculates the highest length match for a given document, and then only return the rows that match on both document name and match length?

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
8
March 10, 2020 - 3:06 pm
sp_Permalink sp_Print sp_EditHistory

Your Match function needs a minor tweak, just add a space after the Document text:

each Text.Contains(Text & " ",[Project])

sp_AnswersTopicAnswer
Answers Post
Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
9
March 10, 2020 - 11:04 pm
sp_Permalink sp_Print

Hi Catalin,  thanks for your tips,  this works for Project number infront with blank

for this type Document 898 LS(T)800/2890DOC,   it will not work,  does it mean that I need to add a  "/" to original value, that will be tedious

if there any other workaround

Thank you !

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
10
March 11, 2020 - 2:12 pm
sp_Permalink sp_Print

The solution is in front of you 🙂

Select the Document column, replace "/" with a space, before using the Match function.

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
11
March 11, 2020 - 2:59 pm
sp_Permalink sp_Print

There is a way to use regular expressions to match complex patterns in power query, if you have messy data.

Here is the function I am using:

(Text as text, Pattern as text)=>
let
RunScript = Web.Page(
"<script>
document.write(
"""&Text&""".match(
new RegExp('"&Pattern&"','g')
).join(';')
);
</script>"
),
Matches = try RunScript{0}[Data]{0}[Children]{1}[Children]{0}[Text] otherwise null
in
Matches

The query is simple, just take the text from a table, the pattern from another table and pass them to the function:

let
Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
Pattern = Excel.CurrentWorkbook(){[Name="Pattern"]}[Content]{0}[Pattern],
#"Added Custom" = Table.AddColumn(Source, "Matches", each FindMatches([Text],Pattern))
in
#"Added Custom"

You can specify in the pattern lots of conditions like: text can be at the beginning, at the end, might be delimited by some chars, and lots of complex scenarios.

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
12
March 11, 2020 - 4:37 pm
sp_Permalink sp_Print

Chris Yap said
Hi Catalin,  thanks for your tips,  this works for Project number infront with blank

for this type Document 898 LS(T)800/2890DOC,   it will not work,  does it mean that I need to add a  "/" to original value, that will be tedious

if there any other workaround

Thank you !  

W

Catalin Bombea said
There is a way to use regular expressions to match complex patterns in power query, if you have messy data.

Here is the function I am using:

<br />
<br />
(Text as text, Pattern as text)=&gt;<br />
let<br />
RunScript = Web.Page(<br />
""<br />
),<br />
Matches = try RunScript{0}[Data]{0}[Children]{1}[Children]{0}[Text] otherwise null<br />
in<br />
Matches<br />
<br />

The query is simple, just take the text from a table, the pattern from another table and pass them to the function:

<br />
<br />
let<br />
Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],<br />
Pattern = Excel.CurrentWorkbook(){[Name="Pattern"]}[Content]{0}[Pattern],<br />
#"Added Custom" = Table.AddColumn(Source, "Matches", each FindMatches([Text],Pattern))<br />
in<br />
#"Added Custom"<br />
<br />

You can specify in the pattern lots of conditions like: text can be at the beginning, at the end, might be delimited by some chars, and lots of complex scenarios. 

Catalin Bombea said
There is a way to use regular expressions to match complex patterns in power query, if you have messy data.

Here is the function I am using:

<br />
<br />
(Text as text, Pattern as text)=&gt;<br />
let<br />
RunScript = Web.Page(<br />
""<br />
),<br />
Matches = try RunScript{0}[Data]{0}[Children]{1}[Children]{0}[Text] otherwise null<br />
in<br />
Matches<br />
<br />

The query is simple, just take the text from a table, the pattern from another table and pass them to the function:

<br />
<br />
let<br />
Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],<br />
Pattern = Excel.CurrentWorkbook(){[Name="Pattern"]}[Content]{0}[Pattern],<br />
#"Added Custom" = Table.AddColumn(Source, "Matches", each FindMatches([Text],Pattern))<br />
in<br />
#"Added Custom"<br />
<br />

You can specify in the pattern lots of conditions like: text can be at the beginning, at the end, might be delimited by some chars, and lots of complex scenarios.  

wow Catalin,  this is too complicated for you,  that is simple for you

if you have time appreciate you can help to code it in my example and I will learn from there,    just like previously I learned the Text function on search substrings from you,  very useful

at the meant time will use replace "/" with ""  haha

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
13
March 11, 2020 - 8:56 pm
sp_Permalink sp_Print

This is the pattern I used:

[A-Z]{2,3}\\(?[A-Z]{1}\\)?[0-9]{3}([A-Z]{1})?([0-9]{1})?

File attached.

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
14
March 11, 2020 - 10:21 pm
sp_Permalink sp_Print

wow Catalin,  amazing,  can explain the pattern in layman term,  really want to learn from you

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
15
March 11, 2020 - 10:43 pm
sp_Permalink sp_Print

If you want to learn regular expressions, you can start here: https://regex101.com/r/wQ4mK9/1

They provide also a playground for JavaScript expressions, used in the power query function.

[A-Z]{2,3}\\(?[A-Z]{1}\\)?[0-9]{3}([A-Z]{1})?([0-9]{1})?

You can see the groups in different colors (i used 5 groups):

first group says that there can be 2 or 3 uppercase letters

second group says that there can be an uppercase letter in paranthesis, the ? says that it might be missing

third group: 3 digits always

4-th group: there can be an uppercase letter, might me missing on some entries (that's what ? symbol means)

group 5: there can be 1 uppercase letter, but might be missing sometimes (?)

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Hans Hallebeek, John IM, Manjula Mangalmurti
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Lawrence Miu
Jo Saies
Paul Pritchard
Monique Roussouw
Keith Aul
Richard Dunks
Manjula Mangalmurti
Thomas Quidort
Jamie Preece
Bob Smith
Forum Stats:
Groups: 3
Forums: 24
Topics: 6192
Posts: 27150

 

Member Stats:
Guest Posters: 49
Members: 31848
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.