Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Selecting values to create a column

I have a column with different informations and I want to separate that information in 3 new columns (Project ID, Project Name, Issue Date).

tiago_cizar_0-1642021217914.png



As you can see in the example, I have the Project ID in row 4 and the value of that ID in row 5, the Project Name in row 6 and the value of that name in row 7, the Issue Date in row 12 and the value of that Date in row 13. I want to create a column Project ID with the value "123456", a column Project Name with the value "blablabla" and Issue Date with the value "July 2020".

Any way to do this?

Thanks!!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

I have a test by your sample.

1.png

I think you can refer to this M code. This code is for situation of your example. In your example, there is only one row in three columns you need. So I use [Index]+1 in "Added Custom" and "Add Custom1" step, you can change the code to  [Index]+n if there are n rows in three columns you need.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WUorViVYy1AsI8vdydXUOUfD0c/MP8nUM8fT3A0uBiYCi/KzU5BIFTxeIciNjE1MzFBm/xNxUsEBSTiIEQaSzfBFSyWlgykjPxd851NfVD4dlnsXFpakKLoklEF1epTmVCkYGRgZgnkt+cmlual6JQlhqUXFmfh5YMMxIKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Cover Sheet" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Cover Sheet", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Added Conditional Column" = Table.AddColumn(#"Added Index", "Custom", each if [Cover Sheet] = "Project ID" then 1 else if [Cover Sheet] = "Project Name" then 2 else if [Cover Sheet] = "Issue Date" then 3 else null),
    #"Added Custom" = Table.AddColumn(#"Added Conditional Column", "Custom.1", each if [Custom] <> null then [Index]+1 else null),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"Custom.1", "Custom"}),
    #"Added Custom1" = Table.AddColumn(#"Filled Down", "Filter", each if [Index] <= [Custom.1] and [Index] >=[Custom.1]-1 then 1 else null),
    #"Replaced Errors" = Table.ReplaceErrorValues(#"Added Custom1", {{"Filter", null}}),
    #"Filtered Rows" = Table.SelectRows(#"Replaced Errors", each ([Filter] = 1)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Index", "Custom.1", "Filter"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns", {"Custom"}, {{"Rows", each _, type table [Cover Sheet=nullable text, Custom=number]}}),
    #"Indexed" = Table.TransformColumns(#"Grouped Rows", {{"Rows", each Table.AddIndexColumn(_,"GroupIndex", 1, 1)}}),
    #"Expanded Rows" = Table.ExpandTableColumn(Indexed, "Rows", {"Cover Sheet", "GroupIndex"}, {"Rows.Cover Sheet", "Rows.GroupIndex"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Expanded Rows", {{"Custom", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Expanded Rows", {{"Custom", type text}}, "en-US")[Custom]), "Custom", "Rows.Cover Sheet"),
    #"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"Rows.GroupIndex"}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Removed Columns1", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Project ID", Int64.Type}, {"Project Name", type text}, {"Issue Date", type date}})
in
    #"Changed Type1"

After transform, result is as below.

2.png

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @Anonymous ,

 

I have a test by your sample.

1.png

I think you can refer to this M code. This code is for situation of your example. In your example, there is only one row in three columns you need. So I use [Index]+1 in "Added Custom" and "Add Custom1" step, you can change the code to  [Index]+n if there are n rows in three columns you need.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WUorViVYy1AsI8vdydXUOUfD0c/MP8nUM8fT3A0uBiYCi/KzU5BIFTxeIciNjE1MzFBm/xNxUsEBSTiIEQaSzfBFSyWlgykjPxd851NfVD4dlnsXFpakKLoklEF1epTmVCkYGRgZgnkt+cmlual6JQlhqUXFmfh5YMMxIKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Cover Sheet" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Cover Sheet", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Added Conditional Column" = Table.AddColumn(#"Added Index", "Custom", each if [Cover Sheet] = "Project ID" then 1 else if [Cover Sheet] = "Project Name" then 2 else if [Cover Sheet] = "Issue Date" then 3 else null),
    #"Added Custom" = Table.AddColumn(#"Added Conditional Column", "Custom.1", each if [Custom] <> null then [Index]+1 else null),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"Custom.1", "Custom"}),
    #"Added Custom1" = Table.AddColumn(#"Filled Down", "Filter", each if [Index] <= [Custom.1] and [Index] >=[Custom.1]-1 then 1 else null),
    #"Replaced Errors" = Table.ReplaceErrorValues(#"Added Custom1", {{"Filter", null}}),
    #"Filtered Rows" = Table.SelectRows(#"Replaced Errors", each ([Filter] = 1)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Index", "Custom.1", "Filter"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns", {"Custom"}, {{"Rows", each _, type table [Cover Sheet=nullable text, Custom=number]}}),
    #"Indexed" = Table.TransformColumns(#"Grouped Rows", {{"Rows", each Table.AddIndexColumn(_,"GroupIndex", 1, 1)}}),
    #"Expanded Rows" = Table.ExpandTableColumn(Indexed, "Rows", {"Cover Sheet", "GroupIndex"}, {"Rows.Cover Sheet", "Rows.GroupIndex"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Expanded Rows", {{"Custom", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Expanded Rows", {{"Custom", type text}}, "en-US")[Custom]), "Custom", "Rows.Cover Sheet"),
    #"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"Rows.GroupIndex"}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Removed Columns1", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Project ID", Int64.Type}, {"Project Name", type text}, {"Issue Date", type date}})
in
    #"Changed Type1"

After transform, result is as below.

2.png

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

Thanks a lot for your answer!!

It works... however, is it possible to apply this to a multiple excel files with the same structure? How would you do this?

 

Thanks,

Tiago Fernandes

Please provide sanitized sample data that fully covers your issue. Paste the data into a table in your post or use one of the file services. Please show the expected outcome.

Anonymous
Not applicable

Hello!!

For now I have this table:

Source.NameCover Sheet
bla iLessons Learned_v11.xlsxnull
bla iLessons Learned_v11.xlsx1. PROJECT INFORMATION
bla iLessons Learned_v11.xlsxnull
bla iLessons Learned_v11.xlsxProject ID
bla iLessons Learned_v11.xlsx123554
bla iLessons Learned_v11.xlsxProject Name
bla iLessons Learned_v11.xlsxbla
bla iLessons Learned_v11.xlsxPjM Name
bla iLessons Learned_v11.xlsxbla bla
bla iLessons Learned_v11.xlsx2. DOCUMENT INFORMATION
bla iLessons Learned_v11.xlsxnull
bla iLessons Learned_v11.xlsxIssue Date
bla iLessons Learned_v11.xlsx12.01.2021
bla iLessons Learned_v11.xlsxDocument Version
bla iLessons Learned_v11.xlsxnull
bla iLessons Learned_v11.xlsx3. TEMPLATE INFORMATION
bla iLessons Learned_v11.xlsxnull
bla iLessons Learned_v11.xlsxTemplate Version
bla iLessons Learned_v11.xlsx1.
bla iLessons Learned_v11.xlsxTemplate Owner
bla iLessons Learned_v11.xlsxBrgP/MFE-PMO
bla iLessons Learned_v11.xlsxnull
bla iLessons Learned_v11.xlsxnull
bla iLessons Learned_v11.xlsxNote:



bla iLessons Learned_v11.xlsx- In case of a change on a role designation is needed according each plant, the entity is allowed to adapt the document to his reality.
bla iLessons Learned_v11.xlsxnull
bla iLessons Learned_v11.xlsxnull
renault iLessons Learned_v1xlsxnull
renault iLessons Learned_v1xlsx1. PROJECT INFORMATION
renault iLessons Learned_v1xlsxnull
renault iLessons Learned_v1xlsxProject ID
renault iLessons Learned_v1xlsx123456
renault iLessons Learned_v1xlsxProject Name
renault iLessons Learned_v1xlsxrenault
renault iLessons Learned_v1xlsxPjM Name
renault iLessons Learned_v1xlsxtiago
renault iLessons Learned_v1xlsx2. DOCUMENT INFORMATION
renault iLessons Learned_v1xlsxnull
renault iLessons Learned_v1xlsxIssue Date
renault iLessons Learned_v1xlsx12.10.2021
renault iLessons Learned_v1xlsxDocument Version
renault iLessons Learned_v1xlsxnull
renault iLessons Learned_v1xlsx3. TEMPLATE INFORMATION
renault iLessons Learned_v1xlsxnull
renault iLessons Learned_v1xlsxTemplate Version
renault iLessons Learned_v1xlsx1.1
renault iLessons Learned_v1xlsxTemplate Owner
renault iLessons Learned_v1xlsxBrgP/MFE-PMO
renault iLessons Learned_v1xlsxnull
renault iLessons Learned_v1xlsxnull
renault iLessons Learned_v1xlsxNote:



renault iLessons Learned_v1xlsx- In case of a change on a role designation is needed according each plant, the entity is allowed to adapt the document to his reality.
renault iLessons Learned_v1xlsxnull
renault iLessons Learned_v1xlsxnull
iLessons Learned_peugeot.xlsxnull
iLessons Learned_peugeot.xlsx1. PROJECT INFORMATION
iLessons Learned_peugeot.xlsxnull
iLessons Learned_peugeot.xlsxProject ID
iLessons Learned_peugeot.xlsx100200
iLessons Learned_peugeot.xlsxProject Name
iLessons Learned_peugeot.xlsxpeugeot
iLessons Learned_peugeot.xlsxPjM Name
iLessons Learned_peugeot.xlsxGabriela 
iLessons Learned_peugeot.xlsx2. DOCUMENT INFORMATION
iLessons Learned_peugeot.xlsxnull
iLessons Learned_peugeot.xlsxIssue Date
iLessons Learned_peugeot.xlsx15.06.2021
iLessons Learned_peugeot.xlsxDocument Version
iLessons Learned_peugeot.xlsxV2
iLessons Learned_peugeot.xlsx3. TEMPLATE INFORMATION
iLessons Learned_peugeot.xlsxnull
iLessons Learned_peugeot.xlsxTemplate Version
iLessons Learned_peugeot.xlsx1.
iLessons Learned_peugeot.xlsxTemplate Owner
iLessons Learned_peugeot.xlsxBrgP/MFE-PMO
iLessons Learned_peugeot.xlsxnull
iLessons Learned_peugeot.xlsxnull
iLessons Learned_peugeot.xlsxNote:



iLessons Learned_peugeot.xlsx- In case of a change on a role designation is needed according each plant, the entity is allowed to adapt the document to his reality.
iLessons Learned_peugeot.xlsxnull
iLessons Learned_peugeot.xlsx

null

 

And I want to achieve this:

ProjectIDProjectNameDate
123554bla12.01.2021
123456renault12.10.2021
100200peugeot

15.06.2021

 

My code looks like this for now:
let
Source = SharePoint.Files("https://bla.sharepoint.com/sites/msteams_7490956/", [ApiVersion = 15]),
#"Filtered Rows" = Table.SelectRows(Source, each ([Extension] = ".xlsm" or [Extension] = ".xlsx")),
#"Filtered Rows1" = Table.SelectRows(#"Filtered Rows", each Text.Contains([Name], "iLessons Learned")),
#"Filtered Hidden Files1" = Table.SelectRows(#"Filtered Rows1", each [Attributes]?[Hidden]? <> true),
#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File", each #"Transform File"([Content])),
#"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
#"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File"}),
#"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File", Table.ColumnNames(#"Transform File"(#"Sample File"))),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Table Column1",{{"Source.Name", type text}, {"Cover Sheet", type any}, {"Column2", type any}, {"Column3", type any}, {"Column4", type any}, {"Column5", type any}, {"Column6", type text}, {"Column7", type any}, {"Column8", type any}, {"Column9", type any}, {"Column10", type any}})
in
#"Changed Type"

 

Thanks!

lbendlin
Super User
Super User

Are these data points always in the same row?  You know that you can address a table row with {rownumber}, right? So the Project ID value would be [Cover Sheet]{4}   (rows start at zero).

No, I didn't know that. How can I use it in this case?

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.