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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
stewartad1
Regular Visitor

Max date with conditions

Hi, 1st time poster here, hope this makes sense.

I need to retreive column "Current Risk Level" from table "RM_ImpactHistory" but with multiple conditions in place:
1. Find the max date but less than or equal to selectedDateTime, this is a variable coming from a slicer using selectedvalue

2. Risk ID being the same between these two tables: RM_ImpactAnalysisImpact and RM_ImpactHistory


Here is my current formula:

CurrRiskLevel =
MAXX(
    FILTER(RM_ImpactHistory,
    RM_ImpactHistory[RiskID] = RM_ImpactAnalysisImpact[RiskID] &&
    RM_ImpactHistory[RM_History.EventDate] <= [SelectedDateTime]
    ),
    RM_ImpactHistory[Current Risk Level]
)

Here's a picture of the report
stewartad1_4-1732642593732.png

Here's a picture of the corresponding data table

stewartad1_1-1732642294096.png

 

When 10/4/2024 4:23:33 PM is selected in the slicer, the expected result for "current risk level" should be "Medium: 12" and that is working. But when 11/6/2024 12:47:49 PM is selected in the slicer, the expected result for "current risk level" should be "Low: 8" and that is not working, it continues to show Medium: 12.

Here's a picture of the two options in the slicer
stewartad1_5-1732642733204.png

 


 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @stewartad1 

 

Please try this:

CurrRiskLevel =
VAR _MaxDate =
    MAXX (
        FILTER (
            ALLSELECTED ( RM_ImpactHistory ),
            RM_ImpactHistory[RiskID] = RM_ImpactAnalysisImpact[RiskID]
                && RM_ImpactHistory[RM_History.EventDate] <= [SelectedDateTime]
        ),
        RM_ImpactHistory[RM_History.EventDate]
    )
RETURN
    CALCULATE (
        SELECTEDVALUE ( RM_ImpactHistory[Current Risk Level] ),
        FILTER (
            ALLSELECTED ( RM_ImpactHistory ),
            RM_ImpactHistory[RM_History.EventDate] = _MaxDate
        )
    )

Don't use aggregate functions to process text-type data, the result of the MAX(RM_ImpactHistory[Current Risk Level]) is Medium: 12 but Low: 8 because the initial M is in front of L.

 

Hope it can help,

 

Best Regards

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

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @stewartad1 

 

Please try this:

CurrRiskLevel =
VAR _MaxDate =
    MAXX (
        FILTER (
            ALLSELECTED ( RM_ImpactHistory ),
            RM_ImpactHistory[RiskID] = RM_ImpactAnalysisImpact[RiskID]
                && RM_ImpactHistory[RM_History.EventDate] <= [SelectedDateTime]
        ),
        RM_ImpactHistory[RM_History.EventDate]
    )
RETURN
    CALCULATE (
        SELECTEDVALUE ( RM_ImpactHistory[Current Risk Level] ),
        FILTER (
            ALLSELECTED ( RM_ImpactHistory ),
            RM_ImpactHistory[RM_History.EventDate] = _MaxDate
        )
    )

Don't use aggregate functions to process text-type data, the result of the MAX(RM_ImpactHistory[Current Risk Level]) is Medium: 12 but Low: 8 because the initial M is in front of L.

 

Hope it can help,

 

Best Regards

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

Hi, that worked, thank you so much!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.