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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
heatherkw
Helper I
Helper I

Find Next Enrollment for Client Based on Certain Conditions

Hello, I am still pretty new to DAX and I have looked around for solutions, but they are not quite the same as my scenario, or I'm just not well-versed enough in DAX to understand how to make it work with my data. 

 

I need to determine if a client returned to our system within 12 months, but several criteria have to be met. Their prior exit must have been to a Permanent Exit Type. Their new enrollment is only counted if it's a certain Program Type as well (Emergency Shelter being one of these). 

 

Here is some made up data as an example of what I would need it to return in the Returns column on the far right. As you can see, Enrollment ID 1234 has a 1 in the return column because they had a permanent exit for that enrollment and then later enrolled in Emergency Shelter again within 12 months. Enrollment ID 1237 has a 0 though because the subsequent enrollment was to a Diversion program, which is not counted and the later Emergency Shelter enrollment was just over 12 months later. Returns are not calculated at all for Non-Permanent Exit Types. 

 

EnrollmentIDPersonalIDEnrollment DateProgramTypeExitDateExitTypeReturned12Months
123412341/1/2018Emergency Shelter4/30/2018Permanent1
123512346/24/2018Emergency Shelter9/21/2018Non-Permanent 
1236123410/1/2018Emergency Shelter10/3/2018Non-Permanent 
1237123412/1/2018Emergency Shelter3/31/2018Permanent0
123812345/1/2019Diversion10/1/2019Non-Permanent 
1239123412/2/2019Emergency Shelter   

 

Thank you for your help!

1 ACCEPTED SOLUTION

Hi @heatherkw ,

According to your description, I enriched my sample.

vkalyjmsft_0-1665135584975.png

I create four scenarios.

1.The next Enrollment is the same PersonalID and ProgramType is Emergency Shelter and within 12 months.

2.The next Enrollment is the same PersonalID and ProgramType isn't Emergency Shelter or Transitional Housing and within 12 months.

3.The next Enrollment isn't the same PersonalID and ProgramType is Emergency Shelter and within 12 months.

4.The next Enrollment is the same PersonalID and ProgramType is Transitional Housing and within 12 months.

 

I modify the formula:

Column =
IF (
    [ExitType] = "Permanent",
    IF (
        MAXX (
            FILTER (
                'Table',
                'Table'[EnrollmentID]
                    = EARLIER ( 'Table'[EnrollmentID] ) + 1
            ),
            'Table'[ProgramType]
        )
            IN { "Emergency Shelter", "Transitional Housing" }
                && DATEDIFF (
                    'Table'[ExitDate],
                    MAXX (
                        FILTER (
                            'Table',
                            'Table'[EnrollmentID]
                                = EARLIER ( 'Table'[EnrollmentID] ) + 1
                        ),
                        'Table'[Enrollment Date]
                    ),
                    MONTH
                ) <= 12
                && 'Table'[PersonalID]
                    = MAXX (
                        FILTER (
                            'Table',
                            'Table'[EnrollmentID]
                                = EARLIER ( 'Table'[EnrollmentID] ) + 1
                        ),
                        'Table'[PersonalID]
                    ),
        1,
        0
    )
)

Get the result.

vkalyjmsft_1-1665136321273.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

6 REPLIES 6
v-yanjiang-msft
Community Support
Community Support

Hi @heatherkw ,

According to your description, here's my solution.

Create a calculated column.

Column =
IF (
    [ExitType] = "Permanent",
    IF (
        MAXX (
            FILTER (
                'Table',
                'Table'[EnrollmentID]
                    = EARLIER ( 'Table'[EnrollmentID] ) + 1
            ),
            'Table'[ProgramType]
        ) = "Emergency Shelter"
            && DATEDIFF (
                'Table'[ExitDate],
                MAXX (
                    FILTER (
                        'Table',
                        'Table'[EnrollmentID]
                            = EARLIER ( 'Table'[EnrollmentID] ) + 1
                    ),
                    'Table'[Enrollment Date]
                ),
                MONTH
            ) <= 12,
        1,
        0
    )
)

Get the result:

vkalyjmsft_0-1665024372968.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I'm also finding that in the real data, this doesn't seem to work. The below records are based on real data. With this calculated field, it returns a 1, but it should return a 0. The person exited to a Permanent destination on both 1/4/2021 and 1/9/2021, and they don't have any enrollment entry dates after 1/9/2021 in any program after that, so it should return a 0. 

EnrollmentIDPersonalIDEntryDateProgramTypeExitDateExitTypeReturn
123488885/28/2020Coordinated Assessment1/4/2021Permanent0
123588886/10/2020PH - Rapid Re-Housing1/9/2021Permanent0

Hi @heatherkw ,

According to your description, I enriched my sample.

vkalyjmsft_0-1665135584975.png

I create four scenarios.

1.The next Enrollment is the same PersonalID and ProgramType is Emergency Shelter and within 12 months.

2.The next Enrollment is the same PersonalID and ProgramType isn't Emergency Shelter or Transitional Housing and within 12 months.

3.The next Enrollment isn't the same PersonalID and ProgramType is Emergency Shelter and within 12 months.

4.The next Enrollment is the same PersonalID and ProgramType is Transitional Housing and within 12 months.

 

I modify the formula:

Column =
IF (
    [ExitType] = "Permanent",
    IF (
        MAXX (
            FILTER (
                'Table',
                'Table'[EnrollmentID]
                    = EARLIER ( 'Table'[EnrollmentID] ) + 1
            ),
            'Table'[ProgramType]
        )
            IN { "Emergency Shelter", "Transitional Housing" }
                && DATEDIFF (
                    'Table'[ExitDate],
                    MAXX (
                        FILTER (
                            'Table',
                            'Table'[EnrollmentID]
                                = EARLIER ( 'Table'[EnrollmentID] ) + 1
                        ),
                        'Table'[Enrollment Date]
                    ),
                    MONTH
                ) <= 12
                && 'Table'[PersonalID]
                    = MAXX (
                        FILTER (
                            'Table',
                            'Table'[EnrollmentID]
                                = EARLIER ( 'Table'[EnrollmentID] ) + 1
                        ),
                        'Table'[PersonalID]
                    ),
        1,
        0
    )
)

Get the result.

vkalyjmsft_1-1665136321273.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hello, someone marked this as a solution, but just letting you know it doesn't work in the real data. It's not returning the correct information at all when we have hundreds of thousands of records. 

Hi @heatherkw ,

Could you please provide a sample, then I would know where it stuck and how to dig.

 

Best Regards,
Community Support Team _ kalyj

Hello! Thank you for this!

 

I have a question. How would I change this if I need to additional program types? For example, I need Transitional Housing as another option, in addition to 3 more.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.