Don't miss your chance to take exam DP-600 or DP-700 on us!
Request nowLearn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
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.
I am further visualizing the number of infractions committed broken down by class. The following is the model view
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 ResultTotal 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 ResultThe 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 ResultStudents 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 ResultThe 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.
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!
Solved! Go to Solution.
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
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 😊
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
Check out the February 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 49 | |
| 40 | |
| 37 | |
| 14 | |
| 13 |
| User | Count |
|---|---|
| 85 | |
| 69 | |
| 37 | |
| 28 | |
| 27 |