Forum Discussion

lbarretta's avatar
lbarretta
Regular Visitor
3 years ago
Solved

Problem with a relationship many to many

Have 2 tables, the relationship between the is one to many. Table1 is like this:   Level facctor 1 1.06 2 0.13 3 40.92 2 1.06   Table2 is: Level ...
  • v-jianboli-msft's avatar
    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.