Forum Discussion
Duplicate rows by merging columns
- 6 years ago
You can achieve using Power Query as below. Locale was used for correct date format, you can consider from Custom1 step.
Custom1 = Extracted dates from ReceivedDate and ResolvedDate columns and splitting them into multiple rows. It will work eveni if difference is more than 1 between dates.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI00jcw1DcyMLQEcYzhnFidaCUjkJAJsrwpQj4WAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, ReceivedDate = _t, ResolvedDate = _t]), #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"ReceivedDate", type date}}, "en-GB"), #"Changed Type" = Table.TransformColumnTypes(#"Changed Type with Locale", {{"ResolvedDate", type date}}, "en-GB"), Custom1 = Table.ExpandListColumn(Table.AddColumn(#"Changed Type","Date",each {Int64.From([ReceivedDate])..Int64.From([ResolvedDate])}),"Date"), #"Changed Type1" = Table.TransformColumnTypes(Custom1,{{"Date", type date}}), #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"ReceivedDate", "ResolvedDate"}) in #"Removed Columns"Thanks
Ankit JainDo Mark it as solution if the response resolved your problem. Do like the response if it seems good and helpful.
I am facing an issue, the IDs which don't have ResolvedDate in the original table, even they are weirdly getting dates. So how to handle this null/blank case?
Also, for some reason all the inserted dates in this new table are wrong.
I want it to be like if:
| ID | ReceivedDate | ResolvedDate |
| 1 | 12/01/2019 | |
| 2 | 14/01/2019 | 15/01/2019 |
Then output should be:
| ID | Date |
| 1 | 12/01/2019 |
| 2 | 14/01/2019 |
| 2 | 15/01/2019 |
Try Below
Custom1 = Table.ExpandListColumn(Table.AddColumn(#"Changed Type","Date",each if [ResolvedDate] = null then {Int64.From([ReceivedDate])} else {Int64.From([ReceivedDate]),Int64.From([ResolvedDate])}),"Date"),Thanks
Ankit Jain
Do Mark it as solution if the response resolved your problem. Do like the response if it seems good and helpful.