Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Data Cleansing Advice Needed

I have a number of data fields that I am trying to cleanse and am trying to find the most efficient way to go about this. Please see below sample of data:    Machine Names: Acritech Hole Popp...
  • zoloturu's avatar
    7 years ago

    Anonymous,

     

    You can solve it in below way:

     

    1. As because there is no common logic between rows then you need to create a dictionary by yourself. So, create a table called 'Dictionary' which will store all correct machine names as below:

     

    (example - link)

     

    2. Create a new blank query and call it fnFuzzyLookup. Then paste below Power Query code there:

     

    (Input as text) => 
    let 
        ListCount = List.Count(Dictionary[Brand]),  
        Result = List.Generate( () => 
                                [
                                    i = 0,
                                    t = Dictionary[Brand]{i},
                                    k = if Text.Middle(Input,0,Text.Length(t)) = t then 1 else 0
                                 ],
                                 each (if ([i] < ListCount and [k] < 2) then true else false),
                                 each [
                                            i = [i] + 1,
                                            t = Dictionary[Brand]{i},
                                            k = if [k] = 1 then 2 else (if (Text.Middle(Input,0,Text.Length(t)) = t) then 1 else 0)  
                                        ],
                                 each (if [k] = 0 then "" else [t])
        )
    in
        List.Last(Result)

    3. Go to the main table (query) and then Add column -> Invoke custom function:

     

    Regards,
    Ruslan
    -------------------------------------------------------------------
    Did I answer your question? Mark my post as a solution!