Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join 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.

Reply
autotest100
Frequent Visitor

How to calculate sums and first sales dates including data of predecessor products?

Hi guys

 

I need a little bit help. I have this table with sales-data:

 

autotest100_0-1729153197818.png

 

How can I get the following result table?

 

autotest100_1-1729153310606.png

 

Thanks for helping.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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"

vcgaomsft_0-1729217613339.png

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

View solution in original post

4 REPLIES 4
autotest100
Frequent Visitor

Thank you to all! All 3 solutions are good solutions.

Anonymous
Not applicable

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"

vcgaomsft_0-1729217613339.png

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

Omid_Motamedise
Super User
Super User

You can use List.Generate also, so provide your sample data here then I can share the code for this problem


If my answer helped solve your issue, please consider marking it as the accepted solution.
wdx223_Daniel
Super User
Super User

=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})

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors