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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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.

3CloudThomas
Super User
Super User

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

 

3CloudThomas
Super User
Super User

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.