Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hello all,
I am still pretty new and I have a challenge I have not been able to overcome. My 'enrollments' table looks like this:
I am looking for a measure (or any other option) that calculates the total number of months each unique student_id was considered "active" for.
For student_id 101, it should be 1 since they were only active in January of 2000.
For student_id 202, it should be 4 since they were active in January and February of 2000, plus January and February of 2001. I can't use the MIN and MAX functions because that would count all months between January 2000 and February 2001, which would be wrong. The student was not active between March 2000 - December 2000.
For student_id 303, it should be 15. The student was active consecutively from January 2000 to January 2001, plus April and May of 2001. Again I can't use the MIN and MAX functions here due to the gap between enrollments, and I also don't want to "double-count" from March 2000 to December 2000 which are accounted for in both enrollment_id's 4 and 5.
Any help would be greatly appreciated.
Solved! Go to Solution.
Hi @JCTX_2
Here's what I would recommend (PBIX attached):
Active Student-Months =
VAR EnrollmentMonths =
GENERATE (
enrollment,
CALCULATETABLE (
VALUES ( 'Date'[Start of Month] ),
DATESBETWEEN (
'Date'[Date],
enrollment[start_month],
enrollment[drop_month]
)
)
)
VAR StudentMonths =
GROUPBY (
EnrollmentMonths,
enrollment[student_id],
'Date'[Start of Month]
)
RETURN
COUNTROWS ( StudentMonths )
This article may be of interest on a related topic:
https://www.daxpatterns.com/events-in-progress/
Regards
Hi @JCTX_2
Here's what I would recommend (PBIX attached):
Active Student-Months =
VAR EnrollmentMonths =
GENERATE (
enrollment,
CALCULATETABLE (
VALUES ( 'Date'[Start of Month] ),
DATESBETWEEN (
'Date'[Date],
enrollment[start_month],
enrollment[drop_month]
)
)
)
VAR StudentMonths =
GROUPBY (
EnrollmentMonths,
enrollment[student_id],
'Date'[Start of Month]
)
RETURN
COUNTROWS ( StudentMonths )
This article may be of interest on a related topic:
https://www.daxpatterns.com/events-in-progress/
Regards