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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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
v-zhengdxu-msft
Community Support
Community Support

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
v-zhengdxu-msft
Community Support
Community Support

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.