Forum Discussion
Text.Remove a specific word in Power Query
- Jul 10, 2024
After your current last step that's probably called #"Unpivoted Other Columns" (otherwise replace it below) add the following:
#"Removed Some Words" = Table.ReplaceValue(#"Unpivoted Other Columns", each [DESCRIPTION], "", (x,y,z)=> List.Accumulate({"BLACK","Black","WHITE","White"},x, (accum,item)=> Text.Replace(accum, item, z) ), {"DESCRIPTION"} )
to get something like:
let ..., #"Changed Type3" = ..., #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type3", {"STYLE No.", "DESCRIPTION", "COLOUR", "EXW (RMB)", "EXW (USD/6.7)", "FREIGHT USD", "LCP USD", "LCP AUD/0.70", "WS AUD GST INC", "FINAL WS AUD", "WS MARGIN", "RRP AUD", "ACTUAL RRP AUD", "RETAIL MARGIN", "TOTAL LCP AUD", "TOTAL PROFIT AUD @100% SELL THROUGH", "TOTAL RETAIL SALES EX GST"}, "Attribute", "Value" ), #"Removed Some Words" = Table.ReplaceValue(#"Unpivoted Other Columns", each [DESCRIPTION], "", (x,y,z)=> List.Accumulate({"BLACK","Black","WHITE","White"},x, (accum,item)=> Text.Replace(accum, item, z) ), {"DESCRIPTION"} ) in #"Removed Some Words"
But that's not ideal:
- The list of words you want to replace is hard-coded
- The replacement should be done before unpivoting other columns (for perf. reasons)
==> See in attached file a better option where there's a ToRemove table with your current words (you can add some others) and look at the order of the steps in the MainTable query
(gonna be off for weeks...)
= Table.UnpivotOtherColumns(#"Changed Type3", {"STYLE No.", "DESCRIPTION", "COLOUR", "EXW (RMB)", "EXW (USD/6.7)", "FREIGHT USD", "LCP USD", "LCP AUD/0.70", "WS AUD GST INC", "FINAL WS AUD", "WS MARGIN", "RRP AUD", "ACTUAL RRP AUD", "RETAIL MARGIN", "TOTAL LCP AUD", "TOTAL PROFIT AUD @100% SELL THROUGH", "TOTAL RETAIL SALES EX GST"}, "Attribute", "Value")
After your current last step that's probably called #"Unpivoted Other Columns" (otherwise replace it below) add the following:
#"Removed Some Words" = Table.ReplaceValue(#"Unpivoted Other Columns", each [DESCRIPTION], "",
(x,y,z)=> List.Accumulate({"BLACK","Black","WHITE","White"},x,
(accum,item)=> Text.Replace(accum, item, z)
),
{"DESCRIPTION"}
)
to get something like:
let
...,
#"Changed Type3" = ...,
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type3",
{"STYLE No.", "DESCRIPTION", "COLOUR", "EXW (RMB)", "EXW (USD/6.7)", "FREIGHT USD", "LCP USD", "LCP AUD/0.70", "WS AUD GST INC", "FINAL WS AUD", "WS MARGIN", "RRP AUD", "ACTUAL RRP AUD", "RETAIL MARGIN", "TOTAL LCP AUD", "TOTAL PROFIT AUD @100% SELL THROUGH", "TOTAL RETAIL SALES EX GST"},
"Attribute", "Value"
),
#"Removed Some Words" = Table.ReplaceValue(#"Unpivoted Other Columns", each [DESCRIPTION], "",
(x,y,z)=> List.Accumulate({"BLACK","Black","WHITE","White"},x,
(accum,item)=> Text.Replace(accum, item, z)
),
{"DESCRIPTION"}
)
in
#"Removed Some Words"
But that's not ideal:
- The list of words you want to replace is hard-coded
- The replacement should be done before unpivoting other columns (for perf. reasons)
==> See in attached file a better option where there's a ToRemove table with your current words (you can add some others) and look at the order of the steps in the MainTable query
(gonna be off for weeks...)
- Eqa33Jul 11, 2024Brass ContributorThanks for your help