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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
heatherkw
Helper I
Helper I

Find minimum date for a client based on several filters not working properly

Hello! I have tried so many combinations of ALLEXCEPT, FILTER, and CALCULATE to try to get a minimum date returned for a client based on several criteria. The difficult thing about the data is that it's messy and there are a lot of records that overlap and don't make a lot of sense, likely due to bad recordkeeping. Below is the actual data I am working with and some cases that are causing me the most trouble, especially #3. The far right column in the table copied below is what I ultimately need to return and use in calculations to get the average time from refer date to enroll date. I need to find the closest referral date after the entry date, then the closest enroll date after that refer date, like a sequence of events. Although client #1 here has two entry dates and two refer dates, only one record really falls into a logical sequence as the refer date is closest to the entry date and the enroll date is then closest to that refer date. 

 

When I try to use FILTER (see example below) after an ALLEXCEPT statement, the results that get returned start to get very messed up. For client #3, when I try to use a FILTER to only select the closest enroll date where the enroll date is after the referral date, the results for some records are correct and for others are not. I can't seem to find a calculation that returns the correct results for all combinations of records. I know there is something about context here that I'm just not understanding, but the filter statement is just not working correctly and I can't figure out how to fix it. 

 

ClosestTimeToEnroll = CALCULATE(MIN('dw CEPathway'[TimeReferToEnroll]),
ALLEXCEPT('dw CEPathway', 'dw CEPathway'[ID], 'dw CEPathway'[EnrollDate]),
FILTER('dw CEPathway',  'dw CEPathway'[EnrollDate] >= 'dw CEPathway'[ReferDate])

 

IDEntryDateTimeToReferReferDateTimeToEnrollEnrollDateClosestTimeToEnroll
18/24/2017199/12/201779/19/2017 
18/24/201716783/29/2022-16529/19/2017 
19/1/2017119/12/201779/19/20177
19/1/201716703/29/2022-16529/19/2017 
22/9/201842/13/20189248/25/2020 
25/4/202005/4/20201138/25/2020113
31/22/201971/29/20195698/20/2020 
31/22/201971/29/20196059/25/2020 
31/22/20195698/13/202078/20/2020 
31/22/20195698/13/2020439/25/2020 
38/22/20193578/13/202078/20/2020 
38/22/20193578/13/2020439/25/2020 
38/22/20194009/25/2020-368/20/2020 
38/22/20194009/25/202009/25/2020 
38/23/20193568/13/202078/20/2020 
38/23/20193568/13/2020439/25/2020 
38/23/20193999/25/2020-368/20/2020 
38/23/20193999/25/202009/25/2020 
34/14/20201218/13/202078/20/20207
34/14/20201218/13/2020439/25/2020 
34/14/20201649/25/2020-368/20/2020 
34/14/20201649/25/202009/25/20200
410/14/2021110/15/20211192/11/2022 
410/14/2021110/15/202143012/19/2022 
410/15/2021010/15/20211192/11/2022119
410/15/2021010/15/202143012/19/2022 

 

1 REPLY 1
Anonymous
Not applicable

Hi @heatherkw ,

I did not find this column in the sample data, can you clarify it?

Which of these results is correct in the expected output?vcgaomsft_0-1684742435537.png

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors