Seperate column in PowerQuery

santnok

Board Regular
Joined
Jan 10, 2014
Messages
97
Hi
I have a tabel in power query excel 2016. In this query I have a tabel like this under here.
My question is, is it posible to split the A column so it will look like the second tabel under here?
In my tabel I have many other coulums to, like Amount, Restamount and som others, but this is not important in what I trying to do.

Tabel 1 Raw data in

A
110018 Customer name<-- Customer number and name
22089<-- Invoice number
310019 Customer name<-- Customer number and name
42000344<-- Invoice number
52000345<-- Invoice number
61001 Customer name<-- Customer number and name
7345<-- Invoice number
867598<-- Invoice number

<tbody>
</tbody>


Tabel 2 Hope to get the result like this.

A (Customer number)B (Customer name)C (Invoice number)
110018Customer name2089
210019Customer name2000344
310019Customer name2000345
41001Customer name345
51001Customer name67598

<tbody>
</tbody>


Hope someone can help me out here :)
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
in your data one customer name has different customer number

so I modified it a bit

srcCust. #Cust. nameinvoice #
10018 Customer name110018Customer name12089
2089​
10019Customer name22000344
10019 Customer name210019Customer name22000345
2000344​
1001Customer name3345
2000345​
1001Customer name367598
1001 Customer name3
345​
67598​

Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table11"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"src", type any}}),
    #"Inserted Text Before Delimiter" = Table.AddColumn(#"Changed Type", "Text Before Delimiter", each Text.BeforeDelimiter(Text.From([src], "en-GB"), " "), type text),
    #"Inserted Text After Delimiter" = Table.AddColumn(#"Inserted Text Before Delimiter", "Text After Delimiter", each Text.AfterDelimiter(Text.From([src], "en-GB"), " "), type text),
    #"Replaced Value" = Table.ReplaceValue(#"Inserted Text After Delimiter","",null,Replacer.ReplaceValue,{"Text After Delimiter"}),
    #"Filled Down" = Table.FillDown(#"Replaced Value",{"Text After Delimiter"}),
    #"Grouped Rows" = Table.Group(#"Filled Down", {"Text After Delimiter"}, {{"Count", each _, type table}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each List.Distinct(Table.Column([Count],"Text Before Delimiter"))),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Custom", Splitter.SplitTextByEachDelimiter({","}, QuoteStyle.Csv, false), {"Custom.1", "Custom.2"}),
    #"Split Column by Delimiter1" = Table.ExpandListColumn(Table.TransformColumns(#"Split Column by Delimiter", {{"Custom.2", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Custom.2"),
    #"Reordered Columns" = Table.ReorderColumns(#"Split Column by Delimiter1",{"Count", "Custom.1", "Text After Delimiter", "Custom.2"}),
    #"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Count"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom.1", "Cust. #"}, {"Text After Delimiter", "Cust. name"}, {"Custom.2", "invoice #"}})
in
    #"Renamed Columns"		[/SIZE]
 
Last edited:
Upvote 0
Hi sandy666
Thank you verry much for the code. :)
Is it to much to ask if you can make a step guide for this. Have and exsisting tabel in power query that I have to change. Have tryid to understand out from the code, but I'm not so steady.

Thanks :) :)
 
Upvote 0
blue table is a simple table from Ctrl+T (Table11) (in Name Manager check it and change to Table11 if necessary)
I changed customer name by adding a number to make them different: 1, 2, 3
then From Table and in Advanced Editor replace all there with code from the post.
then you will see steps in Query Settings - Applied Steps

let me know if it works for you

btw. it doesn't matter where you change the table name, they must be the same in Name Manage and in the code
 
Last edited:
Upvote 0
Thank you verry much for the help :)
I have now recreated my query and I also understand (almost) what you have done. :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,049
Messages
6,122,864
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top