Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredJoin us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.
Hi guys
I need a little bit help. I have this table with sales-data:
How can I get the following result table?
Thanks for helping.
Solved! Go to Solution.
Hi @autotest100 ,
Please refer to the following steps:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZdAxDsIwDAXQq1SZixx/JyE9BCeoMsEOQjBwe+wIN1KoOlRffs5P9z1w1IfDGi6f5fG8397X18InC/RlOhMib/q5ldDW3zjmcQuORUIMVbBQZCiZlbiyyUJIpnqI2Bn4vxu8m1C1brUvGeOYxy04Ful1xG8kaSiZlbgyXsmQltKaZaA0o+Soa+Ku7FjIUHlW2ZXxTMj+8xJCa18=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Product Id" = _t, Product = _t, #"Predecessor Id" = _t, #"First salesdate" = _t, #"Quantity sold" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Product Id", Int64.Type}, {"Product", type text}, {"Predecessor Id", Int64.Type}, {"First salesdate", type date}, {"Quantity sold", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Product2", each Text.Split([Product],"-"){0}),
#"Grouped Rows" = Table.Group(#"Added Custom", {"Product2"}, {{"Data", (x)=>Table.AddColumn(Table.AddColumn(Table.AddIndexColumn(x, "Index", 1, 1, Int64.Type),"Quantity sold incl. predecessors", each List.Sum(List.FirstN(x[Quantity sold],[Index]))), "First salesdate product or predecessors", each Table.SelectRows(x,each [Predecessor Id]=null)[First salesdate]{0})}}),
#"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Product Id", "Product", "Predecessor Id", "First salesdate", "Quantity sold", "Quantity sold incl. predecessors", "First salesdate product or predecessors"}, {"Product Id", "Product", "Predecessor Id", "First salesdate", "Quantity sold", "Quantity sold incl. predecessors", "First salesdate product or predecessors"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Data",{"Product2"})
in
#"Removed Columns"
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
Thank you to all! All 3 solutions are good solutions.
Hi @autotest100 ,
Please refer to the following steps:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZdAxDsIwDAXQq1SZixx/JyE9BCeoMsEOQjBwe+wIN1KoOlRffs5P9z1w1IfDGi6f5fG8397X18InC/RlOhMib/q5ldDW3zjmcQuORUIMVbBQZCiZlbiyyUJIpnqI2Bn4vxu8m1C1brUvGeOYxy04Ful1xG8kaSiZlbgyXsmQltKaZaA0o+Soa+Ku7FjIUHlW2ZXxTMj+8xJCa18=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Product Id" = _t, Product = _t, #"Predecessor Id" = _t, #"First salesdate" = _t, #"Quantity sold" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Product Id", Int64.Type}, {"Product", type text}, {"Predecessor Id", Int64.Type}, {"First salesdate", type date}, {"Quantity sold", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Product2", each Text.Split([Product],"-"){0}),
#"Grouped Rows" = Table.Group(#"Added Custom", {"Product2"}, {{"Data", (x)=>Table.AddColumn(Table.AddColumn(Table.AddIndexColumn(x, "Index", 1, 1, Int64.Type),"Quantity sold incl. predecessors", each List.Sum(List.FirstN(x[Quantity sold],[Index]))), "First salesdate product or predecessors", each Table.SelectRows(x,each [Predecessor Id]=null)[First salesdate]{0})}}),
#"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Product Id", "Product", "Predecessor Id", "First salesdate", "Quantity sold", "Quantity sold incl. predecessors", "First salesdate product or predecessors"}, {"Product Id", "Product", "Predecessor Id", "First salesdate", "Quantity sold", "Quantity sold incl. predecessors", "First salesdate product or predecessors"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Data",{"Product2"})
in
#"Removed Columns"
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
You can use List.Generate also, so provide your sample data here then I can share the code for this problem
=Table.FromRecords(List.Accumulate(Table.ToRecords(YourTable),{{},[],[]},(x,y)=>let a=Record.TransformFields(x{1},{Text.From(y[Product Id]),each y[Quantity sold]+(if Text.From(y[Predecessor Id])??"" = "" then 0 else Record.FieldOrDefault(x{1},Text.From(y[Predecessor Id]),0))},2),b=Record.TransformFields(x{1},{Text.From(y[Product Id]),each if Text.From(y[Predecessor Id])??"" = "" then y[First salesdate] else Record.FieldOrDefault(x{1},Text.From(y[Predecessor Id]),0))},2) in {x{0}&{y&[#"Quantity sod incl. predecessors"=Record.Field(a,Text.From(y[Product Id])),#"First date salesdate product or predecessors"=Record.Field(b,Text.From(y[Product Id]))]},a,b}){0})
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.