Forum Discussion

Mederic's avatar
Mederic
Icon for Post Patron rankPost Patron
1 year ago
Solved

Position of criteria

Hello everyone, I want to indicate the position number if one of the criteria in my list is found in my table1 otherwise 0 Thanks in advance Best regards     Comment currently under...
  • dufoq3's avatar
    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