Forum Discussion

Turduckin's avatar
Turduckin
Frequent Visitor
4 years ago
Solved

Filter Context within variable

Hi all, I'm working on a DAX measure that will provide the count of students who enrolled in classes during their first fall and winter quarters. PBIX File here: https://drive.google.com/file/d/1S...
  • milanpasschier2's avatar
    milanpasschier2
    4 years ago

    Hey Turduckin ,

    Create a calculated column FallAndWinter:

     

     

    FallAndWinter = 
    
    VAR CurrentTypeQuarterName = StudentPersistance[Quarter Name]
    
    VAR CurrentStudentYearTable =
        CALCULATETABLE (
            StudentPersistance,
            ALLEXCEPT ( StudentPersistance, StudentPersistance[Student ID], StudentPersistance[Year] )
        )
    
    VAR HasWinter = FILTER(CurrentStudentYearTable, StudentPersistance[Quarter Name] = "Winter")
    
    RETURN
    
    IF (CurrentTypeQuarterName = "Fall",
        IF (
            NOT(ISBLANK(COUNTROWS(HasWinter))), 1
        )
    )

     

     

    With this you can create a measure to calculate how many of the students are in Fall and Winter in the their first year:

     

     

    Students in Fall And Winter First Year = 
    
    VAR CurrentYear = MAX(StudentPersistance[Year])
    
    VAR StudentTable =
        CALCULATETABLE (
            StudentPersistance,
            ALLEXCEPT ( StudentPersistance, StudentPersistance[Student ID] )
        )
    
    VAR FirstFallAndWinter = MINX(FILTER(StudentTable, StudentPersistance[FallAndWinter] = 1), StudentPersistance[Year])
    
    RETURN
    
    IF (CurrentYear == FirstFallAndWinter, 1)

     

     

     

    Total Students in Fall and Winter First Year = SUMX(VALUES(StudentPersistance[Student ID]), _measures[Students in Fall And Winter First Year])

     

     

    You can download the pbix-file here:

     

    https://milanpasschier2.s3.eu-central-1.amazonaws.com/Com+3.pbix

     

    Best,

     

    Milan