cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ADP5
Helper I
Helper I

Extract specific part of text

Hello,

 

Suppose I have the following string output: abcdefgdd.mm.yyyyhijklmn

 

Let's say it's part of a longer text where "abcdefg" repeats.

 

I'd like to extract "dd.mm.yyyy", which always has the same number of characters even though the characters will differ, using "hijklmn" as a delimiter (("hijklmn") does not repeat in the text).

 

I need an expression that counts and extracts text from right to left. I tried using substring but negative index is not allowed. I somehow managed to do it applying slice to a shorter part of the entire string, but when I incorporated it from the test flow into the main flow with the whole text, it didn't give any result.

 

Any help would be much appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions

If 'abcdefg' is identical in each repeat, then you can split() on that.

 

Use a split() expression with the source of all the text as the first part, and 'abcdefg' is the splitter ... then skip the first pointless value ... something like this:

 

skip(
    split(
    	REFERENCE_TO_YOUR_SOURCE_TEXT,
    	'abcdefg'
    ),
    1
)

 

Replace 'REFERENCE_TO_YOUR_SOURCE_TEXT' with a reference to whatever holds the text.

 

That will create a simple array of strings where the first 10 characters will be what you want. So you could use a Select action with the above in the 'From' field, and (tap the little pen on the right) a 'Map' value of:

 

slice(
	item(),
	0,
	10
)

 

If you want to make that a usable date value, then you could also do this:

 

concat(
	slice(
		item(),
		6,
		10
	),
	'-',
	slice(
		item(),
		3,
		5
	),
	'-',
	slice(
		item(),
		0,
		2
	)
)

 

 

 

Here that is in action:

text splitter 1.pngWith the result:

text splitter 2.pngI used this as my Select from' value:

 

skip(
    split(
    	outputs('SourceText'),
    	'abcdefg'
    ),
    1
)

 

 

View solution in original post

14 REPLIES 14

If 'abcdefg' is identical in each repeat, then you can split() on that.

 

Use a split() expression with the source of all the text as the first part, and 'abcdefg' is the splitter ... then skip the first pointless value ... something like this:

 

skip(
    split(
    	REFERENCE_TO_YOUR_SOURCE_TEXT,
    	'abcdefg'
    ),
    1
)

 

Replace 'REFERENCE_TO_YOUR_SOURCE_TEXT' with a reference to whatever holds the text.

 

That will create a simple array of strings where the first 10 characters will be what you want. So you could use a Select action with the above in the 'From' field, and (tap the little pen on the right) a 'Map' value of:

 

slice(
	item(),
	0,
	10
)

 

If you want to make that a usable date value, then you could also do this:

 

concat(
	slice(
		item(),
		6,
		10
	),
	'-',
	slice(
		item(),
		3,
		5
	),
	'-',
	slice(
		item(),
		0,
		2
	)
)

 

 

 

Here that is in action:

text splitter 1.pngWith the result:

text splitter 2.pngI used this as my Select from' value:

 

skip(
    split(
    	outputs('SourceText'),
    	'abcdefg'
    ),
    1
)

 

 

If the text "abcdefg" is always the same length, then you can use slice.

 

slice({textvalue},7,17)

 

Slice Text.png

 

If 'abcdef' is not the same everytime then you are going to have a harder time, and might want to look into a way to use a regular expression somehow, @ADP5 ...

ah @eliotcole I just thought about using the periods as a reference 💡

 

@ADP5 here is an expression that doesn't matter the length of the text. It functions by referencing where the periods '.' are located. So long as the format dd.mm.yyyy stays the same with the '.' periods then this will work.

 

slice({textvalue},sub(int(indexOf({textvalue},'.')),int(2)),add(int(nthIndexOf({textvalue},'.',2)),5))

 

Slice Text - Using Index of the Periods.png

 

https://learn.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#... 

Nice one, @wskinnermctc  ... 🏆

 


 

Although ... 🤔 ... if I'm reading @ADP5's request rightly ( and I always get things wrong 😅 ) he's asking for each instance of the date in the text. Does yours account for that?

 

Take a look at the text that I fed in to my example ... that's potentially what I believe they are looking at ... and other more randomised versions, of course.

 

I can't think of a way to do this *easily* if the 'abcdefg' is not identical before each date.

 

However I could've sworn I saw something relating to regex recently ... maybe there is a regex hack out there?

Perhaps this needs some office scripts work like what @Paulie78 did here:

https://www.tachytelic.net/2021/04/power-automate-regex/

I don't know. I was just thinking simple terms like single text strings. I guess we'll see when OP replies.

 

(This is speculation and I'm not going to do it; more like entertainment purposes. But if it is like each instance in your example. I wonder if you could get away with counting the number of '.' periods and referencing them like that. *It must only contain periods at the date values* I bet it could be done in some wizard method, since if you split it, there would always be 3 sections for every date.

Anyways, making my head hurt think about it.)

eskay
Frequent Visitor

@eliotcole

I think what you saw were Regex lookaheads.They would work like this:

Input: abcdefgdd.mm.yyyyhijklmn
Regex: .{10}(?=hijklmn)
Output: dd.mm.yyyy

.{10} = Take ten elements of whatever kind

(?=) = which are before the following

hijklmn = String

Aye ... that would be nice.

 

But I really do remember seeing them utilised in Power Automate / Logic Apps somewhere, @eskay, that was more what I was chatting about.

 

On that note, though, if @ADP5 can use Logic Apps, they might be able to leverage more, there. Either via a code block, or a Function App integration. If this is not a commonly run thing, it would only ever end up costing .0000000000000000000003 pence per run or whatever it is for the few actions it would cost. 😉

 

((( @wskinnermctc ☝️)))

@ADP5 

 

You can quite easily achieve this with a single action using Encodian’s Regex Search action. 

the regex expression would be:

 

\d{2}\.\d{2}\.\d{4}

 

Note this is a “Utility” action which only uses 0.05 of an Encodian credit. Therefore an Encodian plan with 500 credits can perform 10,000 Regex searches.

 

ADP5
Helper I
Helper I

@eliotcole @wskinnermctc @eskay @AlexEncodian Thank you very much for your replies. I'm giving you the text below, to be more specific. The part I want to extract is in bold and it appears two times within the text. I only need one of the instances, it doesn't matter which one.

 

{"@odata.type":"#Microsoft.Dynamics.CRM.expando","displayName":"CityDetails","entries@odata.type":"#Collection(Microsoft.Dynamics.CRM.crmbaseentity)","entries":[{"@odata.type":"#Microsoft.Dynamics.CRM.expando","Details":{"@odata.type":"#Microsoft.Dynamics.CRM.expando","value":"Utility - (2.245.985,48-7.546.617,04)-(2.059.932,98-","displayName":"Details","fieldType":"string","text":"Utility - (2.245.985,48-7.546.617,04)-(2.059.932,98-","location":{"@odata.type":"#Microsoft.Dynamics.CRM.expando","pageNumber":1,"boundingBox":{"@odata.type":"#Microsoft.Dynamics.CRM.expando","left":0.0417478438782518,"top":0.4707381475522014,"width":0.3757306021169195,"height":0.013254184496480192,"polygon":{"@odata.type":"#Microsoft.Dynamics.CRM.expando","coordinates@odata.type":"#Collection(Microsoft.Dynamics.CRM.crmbaseentity)","coordinates":[{"@odata.type":"#Microsoft.Dynamics.CRM.expando","x":0.0417478438782518,"y":0.4707381475522014},{"@odata.type":"#Microsoft.Dynamics.CRM.expando","x":0.4174784459951713,"y":0.4707381475522014},{"@odata.type":"#Microsoft.Dynamics.CRM.expando","x":0.4174784459951713,"y":0.4839923320486816},{"@odata.type":"#Microsoft.Dynamics.CRM.expando","x":0.0417478438782518,"y":0.4839923320486816}]}}}}},{"@odata.type":"#Microsoft.Dynamics.CRM.expando","Details":{"@odata.type":"#Microsoft.Dynamics.CRM.expando","value":"7.458.419,03) = 97.854,49 kWh (Company Country SRL:","displayName":"Details","fieldType":"string","text":"7.458.419,03) = 97.854,49 kWh (Company Country SRL:","location":{"@odata.type":"#Microsoft.Dynamics.CRM.expando","pageNumber":1,"boundingBox":{"@odata.type":"#Microsoft.Dynamics.CRM.expando","left":0.04235288451895699,"top":0.4835648079623782,"width":0.3811759678832663,"height":0.012826619635347425,"polygon":{"@odata.type":"#Microsoft.Dynamics.CRM.expando","coordinates@odata.type":"#Collection(Microsoft.Dynamics.CRM.crmbaseentity)","coordinates":[{"@odata.type":"#Microsoft.Dynamics.CRM.expando","x":0.04235288451895699,"y":0.4835648079623782},{"@odata.type":"#Microsoft.Dynamics.CRM.expando","x":0.42352885240222327,"y":0.4835648079623782},{"@odata.type":"#Microsoft.Dynamics.CRM.expando","x":0.42352885240222327,"y":0.49639142759772564},{"@odata.type":"#Microsoft.Dynamics.CRM.expando","x":0.04235288451895699,"y":0.49639142759772564}]}}}}},{"@odata.type":"#Microsoft.Dynamics.CRM.expando","Details":{"@odata.type":"#Microsoft.Dynamics.CRM.expando","value":"30.11.2023)","displayName":"Details","fieldType":"string","text":"30.11.2023)","location":{"@odata.type":"#Microsoft.Dynamics.CRM.expando","pageNumber":1,"boundingBox":{"@odata.type":"#Microsoft.Dynamics.CRM.expando","left":0.04235288451895699,"top":0.5070803044770681,"width":0.0828906435094717,"height":0.014964443941011263,"polygon":{"@odata.type":"#Microsoft.Dynamics.CRM.expando","coordinates@odata.type":"#Collection(Microsoft.Dynamics.CRM.crmbaseentity)","coordinates":[{"@odata.type":"#Microsoft.Dynamics.CRM.expando","x":0.04235288451895699,"y":0.5070803044770681},{"@odata.type":"#Microsoft.Dynamics.CRM.expando","x":0.1252435280284287,"y":0.5070803044770681},{"@odata.type":"#Microsoft.Dynamics.CRM.expando","x":0.1252435280284287,"y":0.5220447484180794},{"@odata.type":"#Microsoft.Dynamics.CRM.expando","x":0.04235288451895699,"y":0.5220447484180794}]}}}}},{"@odata.type":"#Microsoft.Dynamics.CRM.expando","Details":{"@odata.type":"#Microsoft.Dynamics.CRM.expando","value":"97.854,49 kWh) x 0,69351CUR [#HBC3-electric] (01.11.2023 -","displayName":"Details","fieldType":"string","text":"97.854,49 kWh) x 0,69351CUR [#HBC3-electric] (01.11.2023 -","location":{"@odata.type":"#Microsoft.Dynamics.CRM.expando","pageNumber":1,"boundingBox":{"@odata.type":"#Microsoft.Dynamics.CRM.expando","left":0.04235288451895699,"top":0.49553633865028957,"width":0.4235288415832432,"height":0.014109314218745728,"polygon":{"@odata.type":"#Microsoft.Dynamics.CRM.expando","coordinates@odata.type":"#Collection(Microsoft.Dynamics.CRM.crmbaseentity)","coordinates":[{"@odata.type":"#Microsoft.Dynamics.CRM.expando","x":0.04235288451895699,"y":0.49553633865028957},{"@odata.type":"#Microsoft.Dynamics.CRM.expando","x":0.4658817261022002,"y":0.49553633865028957},{"@odata.type":"#Microsoft.Dynamics.CRM.expando","x":0.4658817261022002,"y":0.5096456528690353},{"@odata.type":"#Microsoft.Dynamics.CRM.expando","x":0.04235288451895699,"y":0.5096456528690353}]}}}}}],"columns@odata.type":"#Collection(Microsoft.Dynamics.CRM.crmbaseentity)","columns":[{"@odata.type":"#Microsoft.Dynamics.CRM.expando","name":"Details"}]}

 

The date (which I want to extract) varies, so it's not the same in all texts. The reason I tried to extract it using a delimiter/index that is after it (on the right side of the date) and not before it (on the left side of the date) is because the delimiters/indices after it repeat multiple times in the text.

@ADP5 

As I said, the regex query will pick this up regardless of delimiters, position within text or what the date is as long as it follows format ##.##.####

eskay
Frequent Visitor

Since what you have is a Json format we can also work based on that without using Premium Features. You could read the text as Json, then Power Automate can help with getting to the "value" or "text" bracket and afterwads read the last x chars. Will code a proof of concept later today.

eskay
Frequent Visitor

This would somewhat work:

eskay_0-1707308665444.png

It first transforms the input into a json object, that Power automate recognizes, then goes through all results, cuts out the last couple of characters and checks whether they have two . in them. Would still advise for the regex approach, since its a lot easier to maintain and read, but this could do it without any premium functionality.

Thanks @wskinnermctc for the idea of the . seperation, its a nice somwhat reliabe way to chech, whether im in the right result.

Have attached a sketch of how it could work. Havent checked it it works in practise, probably have a off by one in there in the substring part somewhere.

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,659)