Forum Discussion
Data Cleansing Advice Needed
- 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!
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!
zoloturu absolutely stunning! There was 100% chance that I could not have come up with this on my own! So much gratitude! Thank you!
Question for you, is there a way for me to add a further modification to this Power Query? Everything worked out great but I have a few fields that are null/blank and I have custom names that I would like to fill in.
Ex: Any descr named "Gantry Laser" be updated to = "Tanaka Gantry Laser"? Please see screenshot below.
My hope is to fill the blank/null values with names that I will have the option to custom.
Any guidance will be greatly appreciated!
- zoloturu7 years ago
Memorable Member
Anonymous,
If I understood you correctly then below approach can help you:
1. Go to the table where you plan to add a column.
2. Menu -> Add column -> Custom column
3. Enter a condition similar to below
if Text.Middle([NewColumn],0,12) = "Gantry Laser" then "Tanaka " & [NewColumn] else [NewColumn]
(basically, check if the left side is 'Gantry Laser' then add 'Tanaka' to it or you can use a function Text.Replace)
Text.Middle function reference - https://docs.microsoft.com/en-us/powerquery-m/text-middle
Text.Replace - https://docs.microsoft.com/en-us/powerquery-m/text-replace
Regards,
Ruslan
-------------------------------------------------------------------
Did I answer your question? Mark my post as a solution!- Anonymous7 years agoNot applicable
So much gratitude to you! THANK YOU!
- zoloturu7 years ago
Memorable Member
Anonymous,
You are welcome.
Regards,
Ruslan