Extract and assign a new record

limaalpha

New Member
Joined
Nov 1, 2013
Messages
10
In my table with a title, date and authors columns, each record had multiple authors separated by a semi colon.
I would like to extract the additional author names per row into their own unique records (along with the corresponding data from the original source record).
Can this be done and is it possible to do it in power query so new data extracted can be processed automatically?
 

Attachments

  • Screenshot_20230406_184626_Microsoft 365 (Office).jpg
    Screenshot_20230406_184626_Microsoft 365 (Office).jpg
    155.2 KB · Views: 18

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Take a look at this

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    
    xMaxList =  List.Transform({
        1..List.Max(
         Table.AddColumn(Source, "Custom", each 
            List.Count(
                Text.PositionOfAny([authors], {";"}, Occurrence.All)
            ))[Custom]
        ) +1
    }, each "V" & Text.From(_)),

    sp = Table.SplitColumn(Source, "authors", Splitter.SplitTextByDelimiter("; ", QuoteStyle.Csv), xMaxList),
    unPiv = Table.UnpivotOtherColumns(sp, {"title", "date"}, "Attribute", "authors"),
    delCols = Table.RemoveColumns(unPiv,{"Attribute"})
in
    delCols

Book1
ABCDEFG
1titledateauthorstitledateauthors
2marathon3-4-2023elaine; doug; mikemarathon3-4-2023elaine
3test4-4-2023james; johnmarathon3-4-2023doug
4marathon3-4-2023mike
5test4-4-2023james
6test4-4-2023john
7
Sheet1
 
Upvote 0
Take a look at this

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
   
    xMaxList =  List.Transform({
        1..List.Max(
         Table.AddColumn(Source, "Custom", each
            List.Count(
                Text.PositionOfAny([authors], {";"}, Occurrence.All)
            ))[Custom]
        ) +1
    }, each "V" & Text.From(_)),

    sp = Table.SplitColumn(Source, "authors", Splitter.SplitTextByDelimiter("; ", QuoteStyle.Csv), xMaxList),
    unPiv = Table.UnpivotOtherColumns(sp, {"title", "date"}, "Attribute", "authors"),
    delCols = Table.RemoveColumns(unPiv,{"Attribute"})
in
    delCols

Book1
ABCDEFG
1titledateauthorstitledateauthors
2marathon3-4-2023elaine; doug; mikemarathon3-4-2023elaine
3test4-4-2023james; johnmarathon3-4-2023doug
4marathon3-4-2023mike
5test4-4-2023james
6test4-4-2023john
7
Sheet1
Thank you, I'm nearly there but when I swapped in the real (and extra column names) in the advanced editor, there were no syntax errors but in the main Power Query window I'm getting an "expression. error" any idea where I might have veered off course? see below -

Expression.Error: We cannot convert the value null to type Text.
Details:
Value=
Type=[Type]
 
Upvote 0
Maybe you could post some sample data from your original table
 
Upvote 0
Publication TitlePublication FrequencyDate of SendingPurpose of ContentLima OfficeRelevant AudienceAuthor and BD Contacts
Pub 205Quarterly06/04/2023yet to be determinedGenevaInternalJames; Joanne; Pete
Pub 302Fortnightly21/03/2023generate new audienceFrankfurtClientsChristiana; Mike
 
Upvote 0
try

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Result = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Author and BD Contacts", each Text.Split(_, ";")}}), "Author and BD Contacts")
in
    Result
 
Upvote 0
try

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Result = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Author and BD Contacts", each Text.Split(_, ";")}}), "Author and BD Contacts")
in
    Result
Brilliant! This worked instantly Thank you very much:)
Are there any tutorials you can point me to that cover the transformation features you've utilized to solve this?
 
Upvote 0
Brilliant! This worked instantly Thank you very much:)
Are there any tutorials you can point me to that cover the transformation features you've utilized to solve this?
Spoke too soon :confused:
This worked instantly within the Power Query editor window but when I "close and load to a new worksheet" I get a pop-up error:
[Expression.Error] We Cannot convert the value null to type Text

(ps: Are there any tutorials you can point me to that cover the transformation features you've utilized to solve this?)
 
Upvote 0
Spoke too soon :confused:
This worked instantly within the Power Query editor window but when I "close and load to a new worksheet" I get a pop-up error:
[Expression.Error] We Cannot convert the value null to type Text

(ps: Are there any tutorials you can point me to that cover the transformation features you've utilized to solve this?)
Replace nulls with "" in the authors column before the Result step
 
Upvote 0
Replace nulls with "" in the authors column before the Result step
This worked! I initially tried using the right-click menu "Replace Values..." to replace the string NULL with "". That didn't work but then, I clicked the "Remove Empty" filter option and this eliminated the error. :biggrin:

I realised this filtered out any records that don't have an author so in the source data set, I filtered for this and wrote "No Author" into the fields (copied it down with CTRL+D). Now it's working great! Thanks again.
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,627
Members
452,661
Latest member
Nonhle

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