This is my first attempt at writing more complex DAX measures.
I have table with incidents by student. An incident can have multiple students and a student can have multiple incidents.
I have the below measure to calculate the number of student that have 2 - 6 incidents for the selected period.
Tier 2 =
VAR IncidentByStudentCount =
SUMMARIZE (
FILTER (
IncidentInvolvement,
AND (
IncidentInvolvement[IncidentInvolvementType] = "Involved",
IncidentInvolvement[IncidentCategory] = "Major Negative"
)
),
IncidentInvolvement[SchoolCode],
IncidentInvolvement[StudentIdentifier],
"CountInvolvement", COUNT ( IncidentInvolvement[IncidentCode] )
)
VAR Tier2 =
FILTER (
IncidentByStudentCount,
AND ( [CountInvolvement] >= 2, [CountInvolvement] <= 6 )
)
RETURN
COUNTROWS ( Tier2 ) + 0
Now I want to filter my report page and only show data for the students that have between 2 to 6 incidents for the selected period. What would be the best way to do this?
I tried to solve it with the below measure.
Tier 2 Negative Incidents =
VAR IncidentByStudentCount =
SUMMARIZE(
FILTER(
IncidentInvolvement,
AND (IncidentInvolvement[IncidentInvolvementType] = "Involved",
IncidentInvolvement[IncidentCategory] = "Major Negative")
),
IncidentInvolvement[SchoolCode],
IncidentInvolvement[StudentIdentifier],
"CountInvolvement",
COUNT(IncidentInvolvement[IncidentCode])
)
VAR Tier2Table =
FILTER(
IncidentByStudentCount,
AND ([CountInvolvement] >= 2,
[CountInvolvement] <= 6)
)
VAR Tier2TableFilter =
CALCULATETABLE(
VALUES(IncidentInvolvement[StudentIdentifier]),
Tier2Table,
ALLSELECTED()
)
VAR Tier2NegativeIncidents =
CALCULATE(
COUNT(IncidentInvolvement[IncidentIdentifier]),
AND( IncidentInvolvement[IncidentInvolvementType] = "Involved",
IncidentInvolvement[IncidentCategory] = "Major Negative"
),
Tier2TableFilter)
RETURN
Tier2NegativeIncidents
This works when I have a visual by student. However, for my other visuals where I want to show the number of incidents by location it doesn't work, because it will only show locations for those students where their incident location has between 2-6 incidents. So it executes the filter "AND ([CountInvolvement] >= 2,[CountInvolvement] <= 6)" over the location as well. Clearly I am doing something wrong. I hope someone can help me out!