Forum Discussion
Problem with a relationship many to many
- 3 years ago
Hi lbarretta ,
Please try:
First, duplicate table1, then add a new column cost:
Expanded the cost column:
Then add a new column final cost:
Here is the M code:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTLUMzBTitWJVjICcgz0DI3BHGMgx8RAz9IILgVRFwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Level = _t, factor = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Level", Int64.Type}, {"factor", type number}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "cost", each Table.SelectColumns( Table.SelectRows(Table2, (x)=>x[Level]=[Level]), "Cost")), #"Expanded cost" = Table.ExpandTableColumn(#"Added Custom", "cost", {"Cost"}, {"cost.Cost"}), #"Added Custom1" = Table.AddColumn(#"Expanded cost", "final cost", each [factor]*[cost.Cost]) in #"Added Custom1"Final output:
Best Regards,
Jianbo Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi lbarretta
I recommend you to do it in Power Query like this
Table 1
Table2
Execute a merge
Expand the cost column from table 2
add the final cost column
Result
Best regards
Michael
-----------------------------------------------------
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your thumbs up!
@ me in replies or I'll lose your thread.
-----------------------------------------------------
Hi Mike, sorry if i didn't answer before. what you did look interesting but i didn't realize what the first 2 steps do.