cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mariyahd
Frequent Visitor

Fix Measure to max date between selected dates

Hi all, 

 

I've spent quite a lot of time trying to figure this out. I'm hoping someone can help.

I have a table with the following columns:

LoanID    Date             State

003         05/05/2021   InArrears

003         06/05/2021   Cured

003         11/05/2021   Settled

 

Every loan has a row for each date until it settles.

I also have a calendar table with Date that I'm using as a filter to display number of accounts that have entered arrears in the time period selected in the filter. I need to create a measure that shows the number of loans in specific state at the end of the selected period. 

I tried:

No Of Accts Last State =
var maxdate=MAX('Calendar'[Date])
return
CALCULATE([EnteredArrears],'Table'[Date]=maxdate)
 
EnteredArrears is a measure that calculates he number of loans that have entered arrears during the selected time period.
 
The problem with the above measure is that if a loan settled before the selected maxdate it's excluded. How do I filter for maximum Date <=maxdate and still pull just one row per loan?
 
Thanks,
Mariya

 

1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @mariyahd ,

 

Check the measures.

Measure 1 = 
var _maxdate = CALCULATE(MAX('Table'[Date]),FILTER(ALLEXCEPT('Table','Table'[Loan ID]),'Table'[Date]<=MAX('date'[date])))
return
CALCULATE(MAX('Table'[State]),FILTER('Table','Table'[Date]=_maxdate))

Measure 2 = CALCULATE(DISTINCTCOUNT('Table'[Loan ID]),FILTER('Table','Table'[State]=[Measure 1]))+0

Measure 1 is to get the latest status for each id according to the slicer date.

Measure 2 is to count the ids for each status.

11.PNG

12.PNG 

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

1 REPLY 1
v-jayw-msft
Community Support
Community Support

Hi @mariyahd ,

 

Check the measures.

Measure 1 = 
var _maxdate = CALCULATE(MAX('Table'[Date]),FILTER(ALLEXCEPT('Table','Table'[Loan ID]),'Table'[Date]<=MAX('date'[date])))
return
CALCULATE(MAX('Table'[State]),FILTER('Table','Table'[Date]=_maxdate))

Measure 2 = CALCULATE(DISTINCTCOUNT('Table'[Loan ID]),FILTER('Table','Table'[State]=[Measure 1]))+0

Measure 1 is to get the latest status for each id according to the slicer date.

Measure 2 is to count the ids for each status.

11.PNG

12.PNG 

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

Helpful resources

Announcements
August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors