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.
Hello,
Its not possible to have a relationship between two tables where the primary key between these two tables is duplicated.
You will have a duplication error. or Multiple tables where only 1 table expected message.
What you can do to make the Primary Key between the two tables as unique is to try to Concatenate the Primary key with any other key or identifier, this purpose is to make the PK unique or no valid relationship between the two tables can happen
Hi!
thanks for your prompt answer.
at lest I don't need to modify the structure of the relationship and what i need is that for every record in the second table with level 2 to show 2 records with a different computed final cost...