Pete,

Mike is undoubtedly right but using a set of test data I've not been able to get anything remotely sensible out of a LASTNONBLANK() formula on a set of sample data I created. The documentation is basically non existent and good examples are thin on the ground.

This thread (

DAX: Get sum of values of the last month having data) started by Kasper De Jong contains a discussion of this function however what might be telling about this example and all the examples in Marco and Alberto's new book is that the expression is always based on a separate table. In the versions I came up with, even with the expression contained in CALCULATE() it seemed that the iterative nature of LASTNONBLANK had a strange effect on the filter context.

While I'm keen to see somebody clear this up, I'm still not convinced that it's your answer and as I said previously, I think that the use of EARLIER() and the necessary double iteration are an over complication that this problem doesn't require.

I created this data set to try a few things out. I working on the basis that your requirement is to return the last facility a patient was at where the discharge date was 30 days later than their admission.

The measure I eventually came up with used TOPN to return the top row from a filtered table that was less than the max date for the given filter context where the row satisfied the condition of having 30 days+ between admission and discharge. From that row the VALUES() gives you the facility. Obviously you will need to adapt for your dataset and maybe add a couple of extra conditions to the FILTER() but hopefully this gets you close.

<max(table1[admitdate])&&

Code:

```
=CALCULATE(VALUES(Table1[FAcility]),
TOPN(1,
FILTER(table1,
Table1[AdmitDate]~max(Table1[AdmitDate])&&
Table1[DischargeDate]>=Table1[AdmitDate]+30
),
Table1[AdmitDate])
)
```

NB, I swapped the less than symbol for a ~ to stop the site cutting off half of my formula!!

Let us know how you get on, I uploaded by test model here:

https://docs.google.com/file/d/0Bz5yMU2oooW2YzBzWndVQ0NtdjQ/edit?usp=sharing
Jacob</max(table1[admitdate])&&