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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

extract text between delimiters from the very last

hi guys

 

i need to extract text between delimiter

my start delimiter *

my end delimiter *

 

sometimes i need to extract text from the very last right

 

you may refer to the below screen shot

 

if you observe that i kept my text between delimiters in Red ( Comment column )

*  the yellow represent what will happen if i choose extract function from add column tab ( which sometimes give me wrong output)
*  the blue column that what i need to get.

angle_Fbi_0-1740067463284.png

 

 

 

so how do i get the below column result ?  i need to extract text between delimiters from the last right

 

2 ACCEPTED SOLUTIONS
ronrsnfld
Super User
Super User

Text.BetweenDelimiters([Comments],"*","*",{5,RelativePosition.FromEnd})

ronrsnfld_0-1740139733779.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bcyxCoMwEADQXzkyHi1JTgM2q9DBpdCOJoPQgNJwBzH+f6WLQ/2A98ZRDTIzCIOx2pAmQw6o8c550wTGfsoZ+sS1JLyXaXtfER91TmVFVPFycGr1Pvy47TzdvDWnHA4fOPAgZ7rzrt31c1k/8JK81UX436sYvw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Comments = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Comments", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each 
        Text.BetweenDelimiters([Comments],"*","*",
        {5,RelativePosition.FromEnd}))
in
    #"Added Custom"

 

ronrsnfld_1-1740140070382.png

 

 

View solution in original post

dufoq3
Super User
Super User

Hi @Anonymous, another solution:

 

Output

dufoq3_0-1740140995915.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dcyxCoMwEADQXzkyHpZcTgM2q+DQRWhHzSA0oDRcIMb/r3RxqR/w3jiqR1oEkgAZTayZ2ALXzlpH9STYzTFCF6TkgH2e9zfcABCHsoS8ISpfnQM3+kh+g2kd352hi+EMJrnQrbPNoZ/r9oFXintZk/zxyvsv", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    Ad_Extracted = Table.AddColumn(Source, "Extracted", each Text.BetweenDelimiters(Text.Replace([Column1], "**", "|"), "*", "*", {1, RelativePosition.FromEnd}), type text)
in
    Ad_Extracted

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

9 REPLIES 9
v-nmadadi-msft
Community Support
Community Support

Hi @Anonymous,

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the community members for the issue worked. If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

 

Thanks and regards

v-nmadadi-msft
Community Support
Community Support

Hi @Anonymous ,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

dufoq3
Super User
Super User

Hi @Anonymous, another solution:

 

Output

dufoq3_0-1740140995915.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dcyxCoMwEADQXzkyHpZcTgM2q+DQRWhHzSA0oDRcIMb/r3RxqR/w3jiqR1oEkgAZTayZ2ALXzlpH9STYzTFCF6TkgH2e9zfcABCHsoS8ISpfnQM3+kh+g2kd352hi+EMJrnQrbPNoZ/r9oFXintZk/zxyvsv", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    Ad_Extracted = Table.AddColumn(Source, "Extracted", each Text.BetweenDelimiters(Text.Replace([Column1], "**", "|"), "*", "*", {1, RelativePosition.FromEnd}), type text)
in
    Ad_Extracted

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

ronrsnfld
Super User
Super User

Text.BetweenDelimiters([Comments],"*","*",{5,RelativePosition.FromEnd})

ronrsnfld_0-1740139733779.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bcyxCoMwEADQXzkyHi1JTgM2q9DBpdCOJoPQgNJwBzH+f6WLQ/2A98ZRDTIzCIOx2pAmQw6o8c550wTGfsoZ+sS1JLyXaXtfER91TmVFVPFycGr1Pvy47TzdvDWnHA4fOPAgZ7rzrt31c1k/8JK81UX436sYvw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Comments = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Comments", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each 
        Text.BetweenDelimiters([Comments],"*","*",
        {5,RelativePosition.FromEnd}))
in
    #"Added Custom"

 

ronrsnfld_1-1740140070382.png

 

 

Omid_Motamedise
Super User
Super User

hi, use the following code

let
Source = YourTable,

LastStartPos = Table.AddColumn(Source, "LastStart", each Text.PositionOf([Comment], "*", Occurrence.Last) + 1, Int64.Type),

LastEndPos = Table.AddColumn(LastStartPos, "LastEnd", each Text.PositionOf([Comment], "*", Occurrence.Last, [LastStart]), Int64.Type),

ExtractedText = Table.AddColumn(LastEndPos, "Extracted", each
if [LastStart] > 0 and [LastEnd] > [LastStart] then
Text.Middle([Comment], [LastStart], [LastEnd] - [LastStart])
else
null
),

FinalTable = Table.SelectColumns(ExtractedText, {"Comment", "Extracted"})
in
FinalTable


If my answer helped solve your issue, please consider marking it as the accepted solution.
PwerQueryKees
Super User
Super User

Your problem is multiple lines in one cell.

No worries

= Table.AddColumn(Your_Source_Here, "Custom", each 
let
    lines = Text.Split([Comments], "#(lf)"), // split in lines
    last_line = List.Last(lines)             // get the last line
in 
    Text.BetweenDelimiters(last_line, "*", "*")) // normal extract between delimiters

Produces:

PwerQueryKees_0-1740084364023.png



Did I answer your question? Then please (also) mark my post as a solution and make it easier to find for others having a similar problem.
Remember: You can mark multiple answers as a solution...
If I helped you, please click on the Thumbs Up to give Kudos.

Kees Stolker

A big fan of Power Query and Excel

 

Anonymous
Not applicable

thank you for your reply

i tried to copy and paste your comment into my power query and it wont work it shows me the below

 

angle_Fbi_0-1740939434684.png

 

 

 

 

i will be thankful if you can guide me and tell me what should i do to apply your step into my query.  should i add a step ?  and what do you mean by your_sourse_here?  do you mean my table name?

 

kindly advice

Hi @Anonymous,

Please use get data

vnmadadimsft_0-1741101216304.png

And select the data source where your data which you would like to transform exist.
For ex if we select CSV, we will get M query auto generated like this

vnmadadimsft_1-1741101250102.png

 


and if we choose to manually enter data  

vnmadadimsft_2-1741101250103.png

We will get the M query similar to this

vnmadadimsft_3-1741101267566.png

 

This is how we get your_source_here, After this step go ahead and paste the rest of the code which will help you to transform the data to your desired form.

If you find this post helpful, please mark it as an "Accept as Solution" and consider giving a KUDOS.
Thanks and Regards

 

 

 

Hi @Anonymous ,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If our responses has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.


Thank you.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.