Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Check for character repetition

I am attempting to create a column that checks for character repetition and returns True or False. The value column is made up of sentences. Below is a record of what a fail record in the value colum...
  • ZhangKun's avatar
    1 year ago

    If you mean to check for repeated words, you can split the sentence based on spaces and then check the number of items in the original list and after removing duplicate values.

    let 
        a = Text.Split([value], " ") 
    in 
        List.Count(a) <> List.Count(List.Distinct(a))

     

  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi Anonymous ,

     

    Thanks for your reply.

    Well I think ZhangKun's method is good.

    Here's an example based on his code.

    let
                words = Text.Split([value], " "),
                distinctWords = List.Distinct(words)
            in
                List.Count(words) <> List.Count(distinctWords)

    However, I noticed that you want to start with the fourth word of each row of text and check if there are any words repetition. Please use the following code:

    let
                text = [value],
                words = Text.Split(text, " "),
                wordsToCheck = List.Skip(words, 3),  
                distinctWords = List.Distinct(wordsToCheck)
            in
                List.Count(wordsToCheck) <> List.Count(distinctWords)

     

    Best Regards,

    Stephen Tao

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.