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
Anonymous
Not applicable

Is most recent date

I have a table that has a list of countries, date and value. This table is updated every month with the added new value for countries by month. Every country reports values aty different times and for different months. For example Here ar my most recent values and months

 

County     Date                Value

US            March 2021    1.15

NZ           May 2021       2.3

AU           April 2021      5.4

 

I am trying to add a column so I can filter "ismostrecetdate" for each Country as the dates are always different. I entered the below but then I only receive "yes" for NZ as it has the latest date.

 

IsMostRecentdate = var currentrowdate = FORMAT('United_States,_New_Zealand_and_'[Date], "mm/dd/yyy") var ismostrecentdate = FORMAT(MAX('United_States,_New_Zealand_and_'[Date]), "mm/dd/yyy") return IF(ismostrecentdate = currentrowdate, "yes", "no")
 

Can anyone hlep? The purpose of this is so I can add smart text and values in a text box that automatically update data based off the most recent date of the country I am writing about 

 

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

When you take the MAX, it's calculating the maximum over the whole table instead of just for the current country.

 

You can fix this using ALLEXCEPT to preserve the country row context:

IsMostRecentdate =
VAR currentrowdate =
    FORMAT ( 'United_States,_New_Zealand_and_'[Date], "mm/dd/yyy" )
VAR ismostrecentdate =
    FORMAT (
        CALCULATE (
            MAX ( 'United_States,_New_Zealand_and_'[Date] ),
            ALLEXCEPT (
                'United_States,_New_Zealand_and_',
                'United_States,_New_Zealand_and_'[County]
            )
        ),
        "mm/dd/yyy"
    )
RETURN
    IF ( ismostrecentdate = currentrowdate, "yes", "no" )

 

View solution in original post

2 REPLIES 2
Kumail
Post Prodigy
Post Prodigy

Hello @Anonymous 

 

I just checked with the sample data and its doing fine here. The sample file is attached for your reference.

Kumail_0-1624983528107.png

 

https://drive.google.com/file/d/1nmqGDh3EDv5onnoMXsPwGuPh3Oa62hvt/view?usp=sharing

 

Hope this helps.

 

Regards

Kumail Raza

AlexisOlson
Super User
Super User

When you take the MAX, it's calculating the maximum over the whole table instead of just for the current country.

 

You can fix this using ALLEXCEPT to preserve the country row context:

IsMostRecentdate =
VAR currentrowdate =
    FORMAT ( 'United_States,_New_Zealand_and_'[Date], "mm/dd/yyy" )
VAR ismostrecentdate =
    FORMAT (
        CALCULATE (
            MAX ( 'United_States,_New_Zealand_and_'[Date] ),
            ALLEXCEPT (
                'United_States,_New_Zealand_and_',
                'United_States,_New_Zealand_and_'[County]
            )
        ),
        "mm/dd/yyy"
    )
RETURN
    IF ( ismostrecentdate = currentrowdate, "yes", "no" )

 

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.