Forum Discussion
gigotomo
4 years agoFrequent Visitor
Need to add more rows in powerquery based on a column value.
Hello, I have the following table in power query. I require to add rows based on the duration Hence I need the final table to look like this. Please help
- 4 years ago
Hi gigotomo,
Something like this?
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WqqisUlDSUbLQNzDSNzIwMoKwjWFsEHbMyytNzFHwSU0sS1VQitWJVnJ0coZoMoQohHJM4RxjIHZOLEbT5urmDlZoZIqky8gMzsFiWSwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Employee Name" = _t, #"Start of Leave" = _t, #"End of Leave" = _t, Duration = _t, #"Type of Leave" = _t]), #"Parsed Date" = Table.TransformColumns(Source,{{"Start of Leave", each Date.From(_, "us-en"), type date}, {"End of Leave", each Date.From(_, "us-en"), type date}}), #"Changed Type" = Table.TransformColumnTypes(#"Parsed Date",{{"Employee Name", type text}, {"Start of Leave", type date}, {"End of Leave", type date}, {"Duration", Int64.Type}, {"Type of Leave", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Range", each {Number.From([Start of Leave])..Number.From([End of Leave])}), #"Expanded Range" = Table.ExpandListColumn(#"Added Custom", "Range"), #"Added to Column" = Table.TransformColumns(#"Expanded Range", {{"Range", Date.From, type date}}) in #"Added to Column"Cheers,
John
gigotomo
4 years agoFrequent Visitor
Hello John,
Thanks for the solution but I already found a way using split column. What i did was
1. I created a dummy column with the value "a" repeated the same number of time as duration using Text.Repeat
2. Use "Split Column" but instead of splitting the column into columns, split the column into rows
3. delete the dummy column
But my problem now is how I increment the date value.
jbwtp
Memorable Member
4 years agoHi gigotomo,
Something like this?
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WqqisUlDSUbLQNzDSNzIwMoKwjWFsEHbMyytNzFHwSU0sS1VQitWJVnJ0coZoMoQohHJM4RxjIHZOLEbT5urmDlZoZIqky8gMzsFiWSwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Employee Name" = _t, #"Start of Leave" = _t, #"End of Leave" = _t, Duration = _t, #"Type of Leave" = _t]),
#"Parsed Date" = Table.TransformColumns(Source,{{"Start of Leave", each Date.From(_, "us-en"), type date}, {"End of Leave", each Date.From(_, "us-en"), type date}}),
#"Changed Type" = Table.TransformColumnTypes(#"Parsed Date",{{"Employee Name", type text}, {"Start of Leave", type date}, {"End of Leave", type date}, {"Duration", Int64.Type}, {"Type of Leave", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Range", each {Number.From([Start of Leave])..Number.From([End of Leave])}),
#"Expanded Range" = Table.ExpandListColumn(#"Added Custom", "Range"),
#"Added to Column" = Table.TransformColumns(#"Expanded Range", {{"Range", Date.From, type date}})
in
#"Added to Column"
Cheers,
John