Forum Discussion
Merge row cells
- 1 year ago
Good Day gauravg3,
There will be more elegant ways to do this but here's an approach which works...
- Load the table into Power Query.
- Add an index column (starting at 0).
- Add a conditional column called "Name" with the logic "if the index in the current row is odd populate "Name" with the value of the previous row of the "Start Date" column (which will be a name), otherwise set it as null.
- Tidy up by
- Removing the alternate rows you don't need.
- Removing the index column.
- Extract the date from the "Start Date"
- Set the correct type for the "Name" column.
- Rename columns as you wish (in my example I used "Name" for the name and "Start Date" for the date.
- Reorder columns if you wish.
The result looks as follows
The code looks as follows
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Start Date", type any}, {"Duration A", type number}, {"Duration B", type number}, {"Duraction C", type number}, {"Duration D", type number}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "Name", each if Number.IsOdd([Index]) then #"Changed Type"[Start Date]{[Index]-1} else null),
#"Removed Alternate Rows" = Table.AlternateRows(#"Added Custom",0,1,1),
#"Removed Other Columns" = Table.SelectColumns(#"Removed Alternate Rows",{"Start Date", "Duration A", "Duration B", "Duraction C", "Duration D", "Name"}),
#"Extracted Date" = Table.TransformColumns(#"Removed Other Columns",{{"Start Date", DateTime.Date, type date}}),
#"Changed Type1" = Table.TransformColumnTypes(#"Extracted Date",{{"Name", type text}}),
#"Reordered Columns" = Table.ReorderColumns(#"Changed Type1",{"Name", "Duration A", "Duration B", "Duraction C", "Duration D", "Start Date"})
in
#"Reordered Columns"I've attached an example Excel file.
Hope this helps
Hi gauravg3,
Thanks for reaching out to the Microsoft fabric community forum.
It looks like yoiu are looking for a way to merge two rows. As collinsg and jaineshp have already responded to your query, kindl go through their responses and check if the issue can be resolved.
I would also take a moment to thank collinsg and jaineshp, for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.
If I misunderstand your needs or you still have problems on it, please feel free to let us know.
Best Regards,
Hammad.
- Anonymous11 months agoNot applicable
Hi gauravg3,
As we haven’t heard back from you, so just following up to our previous message. I'd like to confirm if you've successfully resolved this issue or if you need further help.
If yes, you are welcome to share your workaround so that other users can benefit as well. And if you're still looking for guidance, feel free to give us an update, we’re here for you.
Best Regards,
Hammad.
- Anonymous11 months agoNot applicable
Hi gauravg3,
Hope everything’s going smoothly on your end. As we haven’t heard back from you, so I wanted to check if the issue got sorted.
Still stuck? No worries just drop us a message and we can jump back in on the issue.Best Regards,
Hammad.
- Anonymous11 months agoNot applicable
Hi gauravg3,
We noticed there hasn’t been any recent activity on this thread. If you still need support, just drop a reply here and we’ll pick it up from where we left off.Best Regards,
Hammad.