Forum Discussion

dejadpower's avatar
dejadpower
Helper I
2 years ago
Solved

Merge Vs Natural Join

Hi All, I have 3 differrent tables , all are connected with builtin relationships   to achieve my desired output , I created a dax table   Result = SELECTCOLUMNS((NATURALINNERJOIN(Booking...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi dejadpower ,
    Thanks lbendlin  for the prompt reply. I have created some data to solve this issue based on the information you provided and you can follow the steps below:
    1.In Power Query.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCvc3MDAwVNJRCkotzi8tSk5VAHGMDIxM9I30jRBMY6VYHWyqTRFKTJCZcNVGyKqRDDRDMM1xqDbEarYFDtUoSrCpNkZWbYzVbEMDhHITHE4xQ2bGxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Work order" = _t, Resource = _t, #"Start Time" = _t, #"End Time" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Work order", type text}, {"Resource", type text}, {"Start Time", type date}, {"End Time", type date}}),
        #"Appended Query" = Table.Combine({#"Changed Type", #"Resource Table"}),
        #"Removed Alternate Rows" = Table.AlternateRows(#"Appended Query",7,5,13),
        #"Removed Columns" = Table.RemoveColumns(#"Removed Alternate Rows",{"Resource Category"}),
        #"Merged Queries" = Table.NestedJoin(#"Removed Columns", {"Resource"}, #"Resource Table", {"Resource"}, "Resource Table", JoinKind.LeftOuter),
        #"Expanded Resource Table" = Table.ExpandTableColumn(#"Merged Queries", "Resource Table", {"Resource Category"}, {"Resource Table.Resource Category"}),
        #"Pivoted Column" = Table.Pivot(#"Expanded Resource Table", List.Distinct(#"Expanded Resource Table"[#"Resource Table.Resource Category"]), "Resource Table.Resource Category", "Resource", List.Count),
        #"Changed Type1" = Table.TransformColumnTypes(#"Pivoted Column",{{"Painter", Int64.Type}, {"Mason", Int64.Type}, {"Electrician", Int64.Type}, {"Plumber", Int64.Type}})
    in
        #"Changed Type1"

     

    2.Add new Measures.

     

    Start time_ =
    VAR _1 = SELECTEDVALUE( 'Bookings Table'[Work order] )
    CALCULATE (
        MIN ( 'Bookings Table'[Start Time] ),
        FILTER (
            ALL ( 'Bookings Table' ),
            'Bookings Table'[Work order] = _1
        )
    )
    
    End time_ =
    VAR _1 = SELECTEDVALUE( 'Bookings Table'[Work order] )
    CALCULATE (
        MAX ( 'Bookings Table'[End Time] ),
        FILTER (
            ALL ( 'Bookings Table' ),
            'Bookings Table'[Work order] = _1
        )
    )
    
    Days =
    DATEDIFF ( [Start time_], [End time_], DAY ) + 1
    

     

    Fianl output:

    How to Get Your Question Answered Quickly - Microsoft Fabric Community

    If it does not help, please provide more details with your desired out put and pbix file without privacy information.

     

    Best Regards,

    Ada Wang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.