Forum

display the remaind...
 
Notifications
Clear all

display the remainder sub-string of String

4 Posts
2 Users
0 Reactions
131 Views
(@bluesky63)
Posts: 162
Estimable Member
Topic starter
 

Hi,

Sought  from Received from Final Output
AA BB CC BB AA  CC
AA BB CC AA CC BB
AA BB CC CC AA BB
AA BB CC DD DD AA CC BB

each time the number of sub-string in "received from" increases, for e.g  DD AA BB CC (4 nos.),  I need to amend the code in Power Query

any other more efficient way in Power Query to produce final output ?

Thank you !

 

Thank you

 
Posted : 18/01/2020 4:20 am
(@catalinb)
Posts: 1937
Member Admin
 

Try this:

= Table.AddColumn(#"Removed Other Columns", "Custom", each Text.Combine(List.RemoveMatchingItems(Text.Split([Sought from]," "),Text.Split([Received from]," "))," "))

 
Posted : 19/01/2020 1:15 am
(@bluesky63)
Posts: 162
Estimable Member
Topic starter
 

Hi Catalin Sir, 

thanks for your M code,  however when I inserted in the applied steps it gives me error

perhaps you can explain to me the entire codes (insert it in the applied steps) for my learning

Need to consult you on my test query(attached), trying to use another method to achieve what I want,   the last records should have 4 columns and not sure why it transposed to 3 columns only?

 

thank you

 
Posted : 23/01/2020 4:50 am
(@bluesky63)
Posts: 162
Estimable Member
Topic starter
 

Hi Catalin,

thanks for your List.RemoveMatchingItems code,  I think manage to got the solution I want,  the rest will be just some trimming and combining

Really appreciate you vast knowledge on M Coding

 

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Sought from", type text}, {"Received from", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Master", each Text.ToList([Sought from])),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "SubString", each Text.ToList([Received from])),
#"Added Custom2" = Table.AddColumn(#"Added Custom1", "Remove_Match", each List.RemoveMatchingItems([Master],[SubString])),
#"Extracted Values" = Table.TransformColumns(#"Added Custom2", {"Remove_Match", each Text.Combine(List.Transform(_, Text.From)), type text}),
#"Removed Columns" = Table.RemoveColumns(#"Extracted Values",{"Master", "SubString"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Remove_Match", "Final Results"}}),
#"Trimmed Text" = Table.TransformColumns(#"Renamed Columns",{{"Final Results", Text.Trim, type text}})
in
#"Trimmed Text"

 
Posted : 23/01/2020 5:22 am
Share: