Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

SQL to DAX

Two tables, Table A has User/Event/EventDate. Table B has User/InteractionDate.   I would use the following SQL Statement to get a one to many table;       Select A.User, A.Event, A.EventDate,...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous ,

     

    Here I create a sample to have a test.

    A:

    B:

    By Power Query:

    let
        Source = Table.NestedJoin(A, {"User"}, B, {"User"}, "B", JoinKind.LeftOuter),
        #"Expanded B" = Table.ExpandTableColumn(Source, "B", {"User", "InteractionDate"}, {"B.User", "B.InteractionDate"}),
        #"Filtered Rows" = Table.SelectRows(#"Expanded B", each [B.InteractionDate] >= [EventDate] and [B.InteractionDate]<=Date.AddDays([EventDate],30))
    in
        #"Filtered Rows"

     Result is as below.

     

    By Dax:

    Dax Table = 
    VAR _ADD = ADDCOLUMNS(A,"B.User",RELATED(B[User]),"B.InteractionDate",RELATED(B[InteractionDate]))
    VAR _FILTER = FILTER(_ADD,[B.InteractionDate]>=[EventDate]&&[B.InteractionDate]<=[EventDate]+30)
    RETURN
    _FILTER

    Result is as below.

     

    Best Regards,
    Rico Zhou

     

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