Forum Discussion
Position of criteria
- 1 year ago
Hi Mederic,
have you provided correct output? I've created End of position number column for you which is combination of criteria with end of pos number separated by |. As you can see in row 4 - there are 2 matches.
I don't know why do you need such position, but maybe you just want to extract text after this position. If yes, you can delete all steps except Source and Ad_Extract.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("LY69CsMwDAZfRXhuSOy8QTsHOhQ6hAzCdltDIgdFofjt65+u4nTfzbOyJ7MnWROc5DyDjXQIn1ZCJLVcZvUM5AK9gSO6erjFbV+9eAeRYNS9Nr0ZjAF8Sf4fIXnko5IPRjr2yFLIjDVyhA6uCTBwhe4cXZsr1JB9Q59tEzoPoSVMGEg8IVkPWyT5FFn1tOYvcl6S9M8jYbQCWhdPB+5krHpd09Sy/AA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Comment = _t]), Criteria = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W0jcyUtBVUIrVATEN0DlITBjbGCGIwtRF5gDZsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Text = _t]), CritBuffer = List.Buffer(Criteria[Text]), StepBack = Source, Ad_EndOfPositionNumber = Table.AddColumn(StepBack, "End of position number", each [ a = List.Transform(CritBuffer, (x)=> let a1 = Text.PositionOf([Comment], x), a2 = if a1 = -1 then null else Text.Combine({x, Text.From(a1 + Text.Length(x))}, "| ") in a2), b = List.RemoveNulls(a), c = Text.Combine(b, "#(lf)") ][c], type text ), Ad_Extract = Table.AddColumn(Ad_EndOfPositionNumber, "Extract", each [ a = Text.Split([Comment], " "), b = List.PositionOf(List.Transform(a, (x)=> Text.Contains(x, "/")), true), c = Text.Trim(Text.Combine(List.Skip(a, b+1), " "), {" ", "-"}) ][c], type text) in Ad_Extract
Hello dufoq3
Many thanks for this code, which works like a charm,
You're right, it can have 2 positions according to the text.
Otherwise, well done, that's exactly what I wanted the result to be, i.e. the end text after the criteria.
With the position number, I then thought of using the functions: Text.Middle(, Text.PositionOf(), Text.Length()))
But that's no longer necessary, your solution solves everything I wanted in the end
Thank you for your insight
Best regards