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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Add column to validate if Date field is most recent date of that specific month

Hello all,

 

I have a table with projects on one column and Date Updated on another column as in the example below. I would like to add a new column "Most recent date" that will take value 1, if the day when the update took place is the highest in the month and 0 otherwise.

 

In the example below, 15 is the highest day in September and 23 is the highest day in October. That's way the value in the "Most recent date" is 1.

 

Any idea how to achieve this? Also, some intuition along the code will be very helpful. Thank you!

 

Project IDDate UpdatedMost recent date
1102/09/20200
1202/09/20200
1302/09/20200
1402/09/20200
1208/09/20200
1408/09/20200
1215/09/20201
1415/09/20201
1515/09/20201
1615/09/20201
1102/10/20200
1202/10/20200
1302/10/20200
1402/10/20200
1211/10/20200
1411/10/20200
1223/10/20201
1423/10/20201
1523/10/20201
1623/10/20201

 

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Anonymous , a new column like

if( [Date Updated] = maxx(filter(table, format([Date Updated],"YYYYMM") = format(earlier([Date Updated]),"YYYYMM")),[Date Updated]) , 1,0)

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

e1.png

 

You may create a calculated column or a measure as below.

Calculated column:

Result Column = 
var _maxdate = 
CALCULATE(
    MAX('Table'[DateUpdated]),
    FILTER(
        'Table',
        YEAR([DateUpdated])=YEAR(EARLIER('Table'[DateUpdated]))&&
        MONTH([DateUpdated])=MONTH(EARLIER('Table'[DateUpdated]))
    )
)
return
IF(
    [DateUpdated]=_maxdate,
    1,0
)

 

Measure:

Result Measure = 
var _maxdate = 
CALCULATE(
    MAX('Table'[DateUpdated]),
    FILTER(
        ALL('Table'),
        YEAR([DateUpdated])=YEAR(SELECTEDVALUE('Table'[DateUpdated]))&&
        MONTH([DateUpdated])=MONTH(SELECTEDVALUE('Table'[DateUpdated]))
    )
)
return
IF(
    SELECTEDVALUE('Table'[DateUpdated])=_maxdate,
    1,0
)

 

Result:

e2.png

 

Best Regards

Allan

 

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-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

e1.png

 

You may create a calculated column or a measure as below.

Calculated column:

Result Column = 
var _maxdate = 
CALCULATE(
    MAX('Table'[DateUpdated]),
    FILTER(
        'Table',
        YEAR([DateUpdated])=YEAR(EARLIER('Table'[DateUpdated]))&&
        MONTH([DateUpdated])=MONTH(EARLIER('Table'[DateUpdated]))
    )
)
return
IF(
    [DateUpdated]=_maxdate,
    1,0
)

 

Measure:

Result Measure = 
var _maxdate = 
CALCULATE(
    MAX('Table'[DateUpdated]),
    FILTER(
        ALL('Table'),
        YEAR([DateUpdated])=YEAR(SELECTEDVALUE('Table'[DateUpdated]))&&
        MONTH([DateUpdated])=MONTH(SELECTEDVALUE('Table'[DateUpdated]))
    )
)
return
IF(
    SELECTEDVALUE('Table'[DateUpdated])=_maxdate,
    1,0
)

 

Result:

e2.png

 

Best Regards

Allan

 

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

amitchandak
Super User
Super User

@Anonymous , a new column like

if( [Date Updated] = maxx(filter(table, format([Date Updated],"YYYYMM") = format(earlier([Date Updated]),"YYYYMM")),[Date Updated]) , 1,0)

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.