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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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)

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)

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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