Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
AyeshaA10
Frequent Visitor

Filter visual based on filters applied to other visuals

Hi!

I am working with student behavior dataset. I am analyzing the number of infractions committed each semester and comparing with the number committed in the previous semester. 

Screenshot 2023-05-03 092903.jpgI am further visualizing the number of infractions committed broken down by class. The following is the model view

1.jpg

The DAX I'm using to calculate the number of infractions committed in the current and previous semesters are as follows:

Total Infractions Current Semester = VAR CurrentDate = TODAY()
                                     VAR CurrentSemester = CALCULATE(SELECTEDVALUE(Semesters[SemesterID]), CurrentDate >= Semesters[From_Date], CurrentDate <= Semesters[To_Date])
                                     VAR Result = CALCULATE(COUNTROWS('Student Behavior') + 0, 'Student Behavior'[Behavior_Type] = "Infraction", 'DATE'[SemesterID] = CurrentSemester)
                                     RETURN Result
Total Infractions Previous Semester = VAR CurrentDate = TODAY()
	                                  VAR CurrentSemester = CALCULATE(SELECTEDVALUE(Semesters[SemesterID]), CurrentDate >= Semesters[From_Date], CurrentDate <= Semesters[To_Date])
						              VAR PreviousSemester = CurrentSemester - 1
						              VAR Result = CALCULATE(COUNTROWS('Student Behavior') + 0, 'Student Behavior'[Behavior_Type] = "Infraction", 'DATE'[SemesterID] = PreviousSemester)
						              RETURN Result

The DAX I'm using to calculating the number of students who committed infractions in the current and previous semesters are as follows:

Students with Infractions Current Semester = VAR CurrentDate = TODAY()
                                             VAR CurrentSemester = CALCULATE(SELECTEDVALUE(Semesters[SemesterID]), CurrentDate >= Semesters[From_Date], CurrentDate <= Semesters[To_Date])
                                             VAR Result = CALCULATE(DISTINCTCOUNT(Infractions_Table[SID]), ALL('DATE'), 'DATE'[SemesterID] = CurrentSemester)
                                             RETURN Result
Students with Infractions Previous Semester = VAR CurrentDate = TODAY()
                                              VAR CurrentSemester = CALCULATE(SELECTEDVALUE(Semesters[SemesterID]), CurrentDate >= Semesters[From_Date], CurrentDate <= Semesters[To_Date])
                                              VAR PreviousSemester = CurrentSemester - 1
                                              VAR Result = CALCULATE(DISTINCTCOUNT(Infractions_Table[SID]), ALL('DATE'), 'DATE'[SemesterID] = PreviousSemester)
                                              RETURN Result

The issue that I am facing is this:

When I filter one of the visuals, every visual except for 'Students with Infractions - Current Semester' and 'Students with Infractions - Previous Semester' are filtered. I understand that it probably has something to do with distinct counts. 

2.jpg

When the visual 'Infractions by Class - Current Semester' is filtered, how can I have the 'Students with Infractions - Current Semester' visual also filtered to show the number of students who committed infractions in that particular class? Any direction will be hugely appreciated!

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

It looks like the class is on the student behaviour table, so you need to move the filter from there to the infractions table. Try

Students with Infractions Current Semester =
VAR CurrentDate =
    TODAY ()
VAR CurrentSemester =
    CALCULATE (
        SELECTEDVALUE ( Semesters[SemesterID] ),
        CurrentDate >= Semesters[From_Date],
        CurrentDate <= Semesters[To_Date]
    )
VAR Result =
    CALCULATE (
        DISTINCTCOUNT ( Infractions_Table[SID] ),
        ALL ( 'DATE' ),
        'DATE'[SemesterID] = CurrentSemester,
        TREATAS ( VALUES ( 'Student Behaviour'[SID] ), Infractions_Table[SID] )
    )
RETURN
    Result

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

It looks like the class is on the student behaviour table, so you need to move the filter from there to the infractions table. Try

Students with Infractions Current Semester =
VAR CurrentDate =
    TODAY ()
VAR CurrentSemester =
    CALCULATE (
        SELECTEDVALUE ( Semesters[SemesterID] ),
        CurrentDate >= Semesters[From_Date],
        CurrentDate <= Semesters[To_Date]
    )
VAR Result =
    CALCULATE (
        DISTINCTCOUNT ( Infractions_Table[SID] ),
        ALL ( 'DATE' ),
        'DATE'[SemesterID] = CurrentSemester,
        TREATAS ( VALUES ( 'Student Behaviour'[SID] ), Infractions_Table[SID] )
    )
RETURN
    Result

Thank you so much! This worked great. I was not aware of the TREATAS function 😊

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.