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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Mark_Adams
Frequent Visitor

Latest visit based on slicer date

I have a dataset called 'CP Visits' with Case ID and Visit Date. Each case will have several visit dates. There is also a date slicer set to 'between' with dates supplied by a date dimension. I want to pull through the most recent visit for each case that happened before the max date on the date slicer. I can get the most recent visit but can't filter by the slicer.

Using MAX(DateDimension[Date]) in a coulumn just shows the highest date in the date dimension unless I do that as a measure.

1 ACCEPTED SOLUTION
Mark_Adams
Frequent Visitor

Thanks for all the input.

 

I everntually got it sorted myself using 

Most Recent Visit Date =
    CALCULATE(
        MAX('CP Visits'[Visit Date]),
FILTER(
    'CP Visits',
    'CP Visits'[Visit Date] <= [Max Date]
     && 'CP Visits'[Case ID] = SELECTEDVALUE('CP Visits'[Case ID])
)
    )

[Max Date] was from another measure 

= MAXX(ALLSELECTED(DateDimension[Date]), DateDimension[Date])

View solution in original post

7 REPLIES 7
Mark_Adams
Frequent Visitor

Thanks for all the input.

 

I everntually got it sorted myself using 

Most Recent Visit Date =
    CALCULATE(
        MAX('CP Visits'[Visit Date]),
FILTER(
    'CP Visits',
    'CP Visits'[Visit Date] <= [Max Date]
     && 'CP Visits'[Case ID] = SELECTEDVALUE('CP Visits'[Case ID])
)
    )

[Max Date] was from another measure 

= MAXX(ALLSELECTED(DateDimension[Date]), DateDimension[Date])
CoreyP
Solution Sage
Solution Sage

CoreyP_0-1701846323993.png

Filtered:

CoreyP_1-1701846363855.png

You were really close. Just change your MAX field to the fact table, rather than the date table. 

Last Visit = MAX( CPVisits[Date of Visit] )
v-zhangti
Community Support
Community Support

Hi, @Mark_Adams 

 

Can you provide sample data for testing? Sensitive information can be removed in advance. What kind of expected results do you expect? You can also show it with pictures or Excel. I look forward to your response.

 

Best Regards,

Community Support Team _Charlotte

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

Anonymous
Not applicable

You don't have to, the measure will have a context filer from the slicer on the report page.

Unfortunately I can't get TOPN to work at all. It keeps telling me the expression refers to multiple values that cannot be converted to a scalar value

 

Anonymous
Not applicable

that looks like a nice function but I can't work out how to restrict it to visits before the MAX(DateDimension[Date])

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.