Forum Discussion
Split row into multiple rows, while combining columns
Hi,
This M code works
let
Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
#"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Index"}, "Attribute", "Value"),
#"Inserted Text After Delimiter" = Table.AddColumn(#"Unpivoted Other Columns", "Text After Delimiter", each Text.AfterDelimiter([Attribute], " ", 1), type text),
#"Replaced Value" = Table.ReplaceValue(#"Inserted Text After Delimiter","","Milestone",Replacer.ReplaceValue,{"Text After Delimiter"}),
#"Inserted Text Range" = Table.AddColumn(#"Replaced Value", "Text Range", each Text.Middle([Attribute], 10, 1), type text),
#"Removed Columns" = Table.RemoveColumns(#"Inserted Text Range",{"Attribute"}),
#"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[#"Text After Delimiter"]), "Text After Delimiter", "Value"),
#"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"Index", "Text Range"}),
#"Changed Type" = Table.TransformColumnTypes(#"Removed Columns1",{{"target Date", type datetime}})
in
#"Changed Type"
Hope this helps.
The Original dataset is this
Hi Ashish,
Thanks for the detailed response. I'm having some difficulty getting this to work. I already have the dataset in Power BI but these specific columns are just a handful from the whole dataset (150+ columns).
Do you have any advice for how I should tweak this?
Apologies if these are ignorant questions.
- Ashish_Mathur5 years agoSuper User
You are welcome. Without your actual data, I really cannot help much.
- KyleFurner5 years agoFrequent Visitor
I understand. I have created a sample dataset which will demonstrate what I mean.
Essentially I have a dataset where each project's monthly reporting data is contained.
I need to create a subset of this data only containing the information from the following columns:
- Milestone 1
- Milestone 1 Status
- Milestone 1 target Date
- Milestone 2
- Milestone 2 Status
- Milestone 2 target Date
- Milestone 3
- Milestone 3 Status
- Milestone 3 target Date
However, I need to display the data like this:
So I am looking for help to split an this data so that a single row, which has data on multiple milestones for a single project, can be a subset containing a row for each milestone, it's date and it's status. But I don't want to include the extra columns, which in the example above contain data on project RAG ratings, (time/cost/overall status).
- Ashish_Mathur5 years agoSuper User
Hi,
Add the first step in the Query Editor to remove the columns which you do not ant in the output. Let the other steps remain.