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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
tagban
Helper I
Helper I

Measure to find date range an event with date

I have a database with IDs for each unique person, that's linked to various times they were enrolled/disenrolled from our program, and a 3rd set of data that contains events with a single date of when it happened. I'm trying to display the Enrollment/Disenrollment date range that an event happened specifically I have two seperate measures one for enrollment, one for disenrollment but what I'm struggling with is I'm used to looking at MIN/MAX and in reality someone can have multiple enrollments/disenrollments as to when these events fell. Because the logic surrounding this is crucial I wanted to ask here.

The current measure I wrote:

 

 

 

EnrollEnd = 
VAR enrollStart = MIN('Program Modifier Enrollments'[program_modifier_enrollment_start])
VAR enrollEnd = MAX('Program Modifier Enrollments'[program_modifier_enrollment_end_adjusted])
VAR enrollEndWithNull = MAX('Program Modifier Enrollments'[program_modifier_enrollment_end])
VAR assessmentDate = MAX('Events'[assessment_end_date_utc])
VAR StartDate =
    SWITCH(
        TRUE(),
        assessmentDate <= enrollEnd && assessmentDate >= enrollStart,
        1,0
    )
    Return enrollEndWithNull

 

 



The above what I WANT it to do, is pick when the assessment happened and display the date of the enrollment end (as a seperate column). Because this is in a data flow, I have to use measures to build this out. 

The idea here for me, is that I'd have two measures one for Start and one for end dates, that way it displays. But because each person can have multiple start/end dates, it is not correctly assigning the date as expected above. 

Each row in this contains the person's unique ID, and the event date/id, so normally in my head I'd have merged the queries based on the data, but I think the measure is a cleaner option (Or rather the Column). Any support would be greatly appreciated. 

Updated:
Events Table:

person_idevent_dateSpellExpected
72185/14/20161
62192/3/20151
62193/4/20202
55426/17/20211
554211/12/20211
72186/12/20171
72187/1/20222
62196/1/20233
55424/1/20241


Enrollment Table:

person_idenroll_startenroll_endEnrollmentSpellStatus
62191/1/20152/1/20201Disenrolled
72182/3/20163/15/20191Disenrolled
72183/4/2022 2Enrolled
62193/1/20204/1/20202Disenrolled
62194/2/20216/2/20233Disenrolled
55426/15/2021 1Enrolled



Note: Spells are there only to validate results, and aren't actually part of the data source. 

Expected results:

person_idevent_dateSpellExpectedEnroll StartEnroll EndSpell
72185/14/201612/3/20163/15/20191
62192/3/201511/1/20152/1/20201
62193/4/202023/1/20204/1/20202
55426/17/202116/15/2021 1
554211/12/202116/15/2021 1
72186/12/201712/3/20163/15/20191
72187/1/202223/4/2022 2
62196/1/202334/2/20216/2/20233
55424/1/202416/15/2021 1
1 ACCEPTED SOLUTION
tagban
Helper I
Helper I

I did resolve this with a Calculated Column:

a.Assessments_EnrollDateRange = 
VAR CurrentEventDate = 'Assessments'[assessment_start_date]
VAR CurrentMemberID = 'Assessments'[people_id]
VAR Result =
    CALCULATE (
        VAR StartDate = SUM('Enrollments'[enrollment_start].[Date])
        VAR EndDate = SUM('Enrollments'[enrollment_end_adjusted].[Date])
        RETURN
        IF (
            NOT ISBLANK(StartDate) && NOT ISBLANK(EndDate),
            CONCATENATE(StartDate, CONCATENATE(" - ", EndDate) ),
            BLANK()
        ),
        FILTER (
            ALL ( 'Enrollments' ),
            'Enrollments'[people_id] = CurrentMemberID &&
            CurrentEventDate >= 'Enrollments'[enrollment_start] &&
            CurrentEventDate <= 'Enrollments'[enrollment_end_adjusted]
        )
    )
VAR MostRecentEnrollment =
    CALCULATE (
        CONCATENATE(
            MAX('Enrollments'[enrollment_start].[Date]),
            CONCATENATE(" - ", MAX('Enrollments'[enrollment_end_adjusted].[Date])
        )),
        FILTER (
            ALL ( 'Enrollments' ),
            'Enrollments'[people_id] = CurrentMemberID &&
            'Enrollments'[enrollment_start] <= CurrentEventDate
        )
    )
RETURN
IF ( ISBLANK ( Result ), MostRecentEnrollment, Result )

View solution in original post

4 REPLIES 4
tagban
Helper I
Helper I

I did resolve this with a Calculated Column:

a.Assessments_EnrollDateRange = 
VAR CurrentEventDate = 'Assessments'[assessment_start_date]
VAR CurrentMemberID = 'Assessments'[people_id]
VAR Result =
    CALCULATE (
        VAR StartDate = SUM('Enrollments'[enrollment_start].[Date])
        VAR EndDate = SUM('Enrollments'[enrollment_end_adjusted].[Date])
        RETURN
        IF (
            NOT ISBLANK(StartDate) && NOT ISBLANK(EndDate),
            CONCATENATE(StartDate, CONCATENATE(" - ", EndDate) ),
            BLANK()
        ),
        FILTER (
            ALL ( 'Enrollments' ),
            'Enrollments'[people_id] = CurrentMemberID &&
            CurrentEventDate >= 'Enrollments'[enrollment_start] &&
            CurrentEventDate <= 'Enrollments'[enrollment_end_adjusted]
        )
    )
VAR MostRecentEnrollment =
    CALCULATE (
        CONCATENATE(
            MAX('Enrollments'[enrollment_start].[Date]),
            CONCATENATE(" - ", MAX('Enrollments'[enrollment_end_adjusted].[Date])
        )),
        FILTER (
            ALL ( 'Enrollments' ),
            'Enrollments'[people_id] = CurrentMemberID &&
            'Enrollments'[enrollment_start] <= CurrentEventDate
        )
    )
RETURN
IF ( ISBLANK ( Result ), MostRecentEnrollment, Result )
v-yaningy-msft
Community Support
Community Support

Hi, @tagban 

If a person registers multiple times, is his ID the same? You can work with non-sensitive data screenshots to aid in understanding your needs or share pbix files, all text is really not easy to understand.

Best Regards,
Yang
Community Support Team

I've done a lot of logic checks, and testing, I came up with what I thought made sense but its just showing the Max for the entire list of enrollment dates and not individualizing each person's enrollment date aligned with when the event happened. Here's my measure (Slightly altered to be less confusing since our table naming conventions leave a lot to be desired)
I feel like I'm missing a step to properly align the people_id from Enrollments with the assessment so I only get the various enrollment spans that that particular person has.

 

EnrollRange_ASSESSMENT = 
  VAR __date = MAX('ASSESSMENT'[assessment_start_date])
  VAR __ID = MAX('ASSESSMENT'[people_id])
  VAR __EnrollRange = 
    MAXX(
      FILTER(
        'ENROLLMENTS',
        'ENROLLMENTS'[people_id] = __ID &&
          __date >= 'ENROLLMENTS'[enrollment_start] &&
            __date <= 'ENROLLMENTS'[enrollment_end]
      ),
    CONCATENATE(
	'ENROLLMENTS'[enrollment_start].[Date], 
		CONCATENATE(" - ",'ENROLLMENTS'[enrollment_end_adjusted].[Date]))
    )
RETURN
  __EnrollRange

 

Worth noting that the end_adjusted is always a future date when they're currently enrolled. (And yes I know the one above I forgot to leave it there, so jsut assume its there, I can't seem to edit it?

I do understand the request for pbix/pictures. What I can do is maybe make a table of data to play with. The data I'm using is mostly very sensitive and cannot be exposed publicly unfortunately. I'll respond with an updated data set to work with shortly. Thanks!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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