Forum Discussion

Kimber's avatar
Kimber
Helper III
1 year ago
Solved

Using TREATAS to join 2 tables

I am trying to combine two tables together that are the SQL equivalent of      SELECT s.StudentId, s.[School Year], s.School, a.Date, a.[Expected Amount], a.[Present Amount] FROM PowerBIActiveAnd...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi Kimber

     

    Based on my tests, TREATAS cannot directly reference the FilteredStudents variable.

     

    Try the following workaround:

     

    NewTable2 = 
    VAR FilteredStudents =
        SELECTCOLUMNS(
            FILTER(
                'PowerBI ActiveAndInactiveStudentsWithLastSchool_2Yrs',
                [IsActive] = 1
            ),
            "StudentId", [StudentId],
            "Key_Year", [Key_Year],
            "School", [School]
        )
    RETURN
    DISTINCT(
        SELECTCOLUMNS(
            FILTER(
                'PowerBI StudentAttendanceByDay_2Yrs',
                'PowerBI StudentAttendanceByDay_2Yrs'[StudentId] IN DISTINCT(SELECTCOLUMNS(FilteredStudents, "StudentId", [StudentId]))
                &&
                'PowerBI StudentAttendanceByDay_2Yrs'[Key_Year] IN DISTINCT(SELECTCOLUMNS(FilteredStudents, "Key_Year", [Key_Year]))
                &&
                'PowerBI StudentAttendanceByDay_2Yrs'[School] IN DISTINCT(SELECTCOLUMNS(FilteredStudents, "School", [School]))
            ),
            "StudentId", 'PowerBI StudentAttendanceByDay_2Yrs'[StudentId],
            "School Year", 'PowerBI StudentAttendanceByDay_2Yrs'[School Year],
            "School", 'PowerBI StudentAttendanceByDay_2Yrs'[School],
            "Date", 'PowerBI StudentAttendanceByDay_2Yrs'[Date],
            "Expected Amount", 'PowerBI StudentAttendanceByDay_2Yrs'[Expected Amount],
            "Present Amount", 'PowerBI StudentAttendanceByDay_2Yrs'[Present Amount]
        ))
    

    For more detailed information, please see the attachment.