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
sfooshee
Regular Visitor

Return the last date with criteria

I couldn't find anything that answered this so I thought I would ask it here. I'm trying to create a calculated column in BI that displays each patient's first visit date. I have tried LASTDATE and MAX and can't quite figure it out. 

 

Basically, the cell needs to display the most recent visit date from a row where that meets these criteria:

  1. The patient ID matches the current row (I usually use the EARLIER function)
  2. Completed = "Yes"
  3. Patient Status = "New"

Attached below is a sample data table and a screenshot of the result.

 

Thank you so much!

 

Patient IDVisit DateCompletedPatient StatusFirst Visit Date
11/1/21YesNew 
21/2/21YesNew 
31/3/21NoNew 
31/4/21YesNew 
18/31/21YesActive 
19/1/21YesActive 
29/2/21YesActive 
39/3/21YesActive 

 

Screen Shot 2021-08-31 at 3.52.44 PM.png

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

First Visit Date =
MINX (
    FILTER (
        'Table',
        'Table'[Patient ID] = EARLIER ( 'Table'[Patient ID] )
            && 'Table'[Patient Status] = "New"
            && 'Table'[Completed] = "Yes"
    ),
    'Table'[Visit Date]
)

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

First Visit Date =
MINX (
    FILTER (
        'Table',
        'Table'[Patient ID] = EARLIER ( 'Table'[Patient ID] )
            && 'Table'[Patient Status] = "New"
            && 'Table'[Completed] = "Yes"
    ),
    'Table'[Visit Date]
)

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

@CNENFRNL That's perfect. Thanks so much!

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.

Top Solution Authors