Forum Discussion
Add duplicate row based on column
- 4 months ago
Hi jwb3d , from your query, I beleive you need to duplicate same rows if the Phase count is more than one value .
IP :
Use Table .Repeat fundtion to handle this scenariolet Source = #"IP Table", // -> Source table ColNames = Table.ColumnNames(Source), // Nest each row as a repeated table AddedRepeated = Table.AddColumn( Source, "RepeatedRows", each Table.Repeat( Table.FromRecords({ _ }), [phaseCount] ) ), // the id is causing error so drop originals BEFORE expanding to avoid duplicate field error OnlyNested = Table.SelectColumns(AddedRepeated, {"RepeatedRows"}), Expanded = Table.ExpandTableColumn( OnlyNested, "RepeatedRows", ColNames ), #"Added Index" = Table.AddIndexColumn(Expanded, "Index", 1, 1, Int64.Type) in #"Added Index"
OP:
Sample :
Row Expand.pbix
Thanks
If you found this helpful, please consider giving it a kudo and marking it as the accepted solution — it goes a long way in helping others facing the same issue.
For more Power BI tips and discussions, let’s connect on LinkedIn:
https://www.linkedin.com/in/natarajan-manivasagan
Cheers! - 4 months ago
if you want to add duplicate rows, you can add a list.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwtDAwMDcyUtJRMgZiRydnIGlgrOubWKRrZAZku6SWZSanGirF6oBVm5hamJoYAsVB2BGrWiOYWgsDQyNjA6haJ6xqjcFqDQ0NjIwMLI0sgOIgl+BwhIlSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [fid = _t, phaseCount = _t, phase = _t, extractDate = _t, deviceName = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"fid", Int64.Type}, {"phaseCount", Int64.Type}, {"phase", type text}, {"extractDate", type date}, {"deviceName", type text}}), #"Replaced Value" = Table.ReplaceValue(#"Changed Type",null,null,(old,new,z)=>List.Repeat({old}, Text.Length(old)),{"phase"}), #"Expanded {0}" = Table.ExpandListColumn(#"Replaced Value", "phase") in #"Expanded {0}" - 4 months ago
pls try
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwtDAwMDcyUtJRMgZiRydnIGlgrOubWKRrZAZku6SWZSanGirF6oBVm5hamJoYAsVB2BGrWiOYWgsDQyNjA6haJ6xqjcFqDQ0NjIwMLI0sgOIgl+BwhIlSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [fid = _t, phaseCount = _t, phase = _t, extractDate = _t, deviceName = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"phaseCount", type number}}), lst = Table.ColumnNames(#"Changed Type"), from = List.TransformMany(Table.ToRows(#"Changed Type"), (x)=> {1..x{1}},(x,y)=>x), tb = Table.FromRows(from,lst) in tb
Hi jwb3d , from your query, I beleive you need to duplicate same rows if the Phase count is more than one value .
IP :
Use Table .Repeat fundtion to handle this scenario
let
Source = #"IP Table", // -> Source table
ColNames = Table.ColumnNames(Source),
// Nest each row as a repeated table
AddedRepeated = Table.AddColumn(
Source,
"RepeatedRows",
each Table.Repeat( Table.FromRecords({ _ }), [phaseCount] )
),
// the id is causing error so drop originals BEFORE expanding to avoid duplicate field error
OnlyNested = Table.SelectColumns(AddedRepeated, {"RepeatedRows"}),
Expanded = Table.ExpandTableColumn(
OnlyNested, "RepeatedRows", ColNames
),
#"Added Index" = Table.AddIndexColumn(Expanded, "Index", 1, 1, Int64.Type)
in
#"Added Index"
OP:
Sample :
Row Expand.pbix
Thanks
If you found this helpful, please consider giving it a kudo and marking it as the accepted solution — it goes a long way in helping others facing the same issue.
For more Power BI tips and discussions, let’s connect on LinkedIn:
https://www.linkedin.com/in/natarajan-manivasagan
Cheers!
- jwb3d4 months agoFrequent Visitor
I would like to include a column that is derived from the deviceName and phase. This would involve appending A-B-C to each of the duplicated rows.
Example
fid phaseCount phase extractDate deviceName Index New Column 201800722 3 ABC 3/3/2026 Device1 1 Device1A 201800722 3 ABC 3/3/2026 Device1 2 Device1B 201800722 3 ABC 3/3/2026 Device1 3 Device1C 821047293 2 AC 3/3/2026 Device10 19 Device1A 821047293 2 AC 3/3/2026 Device10 20 Device1B 720183650 1 D 3/3/2026 Device9 18 Device9D