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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Flpowerbi01
Frequent Visitor

Create a flag for the latest date before today and another flag for the closest date last year

Hi All, 

 

I am trying to create a flag for the latest date before today and another flag for the closest date last year. Below shows what I want to achieve, this would be the third column: 

 

 

DateDate Description Latest Date and Latest Date Last Year
07/06/2023     0N
10/05/2023   0N
12/04/20230N
15/03/20230N
15/02/20231Y
18/01/20232N
21/12/20223N
23/11/20224N
26/10/20225N
28/09/20226N
31/08/20227N
03/08/20228N
06/07/20229N
08/06/202210N
11/05/202211N
12/04/202212N
16/03/202213N
16/02/202214Y
19/01/202215N
22/12/202116N
24/11/202117N

 

 

This would be the table if today() was 22/02/23.

 

Thank you so much!

 

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @Flpowerbi01 

try to add a calculated column like:

FlagColumn =
VAR _date1 =
MAXX(
     FILTER(
        TableName,
        TableName<TODAY()
    ),
   TableName[Date]
)
VAR _date2 =
MAXX(
     FILTER(
        TableName,
        TableName<EDATE(TODAY(), -12)
    ),
   TableName[Date]
)
VAR _date3 =
MINX(
     FILTER(
        TableName,
        TableName>EDATE(TODAY(), -12)
    ),
   TableName[Date]
)
RETURN
IF(
    [Date] IN {_date1, _date2, _date3},
    "Y", "N"
)

View solution in original post

2 REPLIES 2
Flpowerbi01
Frequent Visitor

Thank you so much for this! 😀

FreemanZ
Super User
Super User

hi @Flpowerbi01 

try to add a calculated column like:

FlagColumn =
VAR _date1 =
MAXX(
     FILTER(
        TableName,
        TableName<TODAY()
    ),
   TableName[Date]
)
VAR _date2 =
MAXX(
     FILTER(
        TableName,
        TableName<EDATE(TODAY(), -12)
    ),
   TableName[Date]
)
VAR _date3 =
MINX(
     FILTER(
        TableName,
        TableName>EDATE(TODAY(), -12)
    ),
   TableName[Date]
)
RETURN
IF(
    [Date] IN {_date1, _date2, _date3},
    "Y", "N"
)

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.