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
gmasta1129
Helper IV
Helper IV

Find if a date changes

Hello, 

 

I have a report that contains 3 columns

 

1. Run Date

2. Portfolio Code

3. Maturity Date

 

I am trying to create a formula to show if there is a difference in the maturity date column from one day to the next by portfolio code. 

Please see table below for reference. 

From Run Date 10/6/2025 to 10/7/2025, the date changed to 6/30/2028. Therefore the new column should show a "Y".  

From Run Date 10/7/2025 to 10/8/2025, the date changed again to 6/27/2027. Therefore the new column should show a "Y".  If there is no change then a "N" should show.  

 

Run Datefacility codematurity dateDate Change? 
10/1/2025718036/27/2027N
10/2/2025718036/27/2027N
10/3/2025718036/27/2027N
10/6/2025718036/27/2027N
10/7/2025718036/30/2028Y
10/8/2025718036/27/2027Y
10/9/2025718036/27/2027N
10/10/2025718036/27/2027N

 

 

Can someone please help with the formula? 

 

Thanks in advance for your help. 

6 REPLIES 6
raisurrahman
Frequent Visitor

@gmasta1129:
Thanks to @ronrsnfld  and @AntrikshSharma for their Power Query solutions—both work perfectly. For very large datasets, I’d recommend @ronrsnfld's approach; it’s faster than @AntrikshSharma ’s, because the latter transforms the object multiple times (Table → Record → Table). 

Kedar_Pande
Super User
Super User

  

Add a calculated column:

Date Change? =
VAR CurrentPortfolio = 'Table'[Portfolio Code]
VAR PreviousDate =
CALCULATE(
MAX('Table'[Maturity Date]),
FILTER(
'Table',
'Table'[Portfolio Code] = CurrentPortfolio &&
'Table'[Run Date] < EARLIER('Table'[Run Date])
)
)
RETURN
IF('Table'[Maturity Date] <> PreviousDate && NOT ISBLANK(PreviousDate), "Y", "N")
 

@gmasta1129

AntrikshSharma
Super User
Super User

@gmasta1129  Try this:

 

let
    Source = Excel.CurrentWorkbook(){[ Name = "Table1" ]}[Content],
    ChangedType = Table.TransformColumnTypes (
        Source,
        { { "Run Date", type date }, { "facility code", Int64.Type }, { "maturity date", type date } }
    ),
    Recs = Table.ToRecords ( ChangedType ),
    Acc = List.Accumulate (
        List.Skip ( Recs ),
        { List.First ( Recs, 1 ) & [ Date Change = "N" ] },
        ( s, c ) =>
            s
                & {
                    if List.Last ( s )[#"maturity date"] <> c[#"maturity date"] then
                        c & [ Date Change = "Y" ]
                    else
                        c & [ Date Change = "N" ]
                }
    ),
    Result = Table.FromRecords (
        Acc,
        type table [ Run Date = date, facility code = Int64.Type, maturity date = date, Date Change = text ]
    )
in
    Result

 

Excel file attached below.

ronrsnfld
Super User
Super User

In Power Query, you can add an Index column to refer to the previous row.

 

Paste the below code into the Advanced Editor to see how it works:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjTQN9Q3MjAyVdJRMje0MDAG0mb6RuYgMXOlWB2wCiOCKowJqjAjqMIcU4WxAUjMAqbCgqAZlgRVGBrgURILAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Run Date" = _t, #"facility code" = _t, #"maturity date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Run Date", type date}, {"facility code", Int64.Type}, {"maturity date", type date}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Change?", each 
        if [Index] = 0 then "N" 
        else if #"Changed Type"[maturity date]{[Index]-1} = [maturity date] then "N" else "Y", type text)
in
    #"Added Custom"
SundarRaj
Super User
Super User

Hi @gmasta1129,
In case you'd like to do this query on Power Query. Here's a solution that you can refer to. Let me know in case there are any confusions. Thanks

SundarRaj_0-1760185717363.png

Code:
let
Source = [SourceData],
Group = Table.Group(
Source,
{"facility code"},
{
{
"AllRows",
each
let
AddColumn = Table.AddIndexColumn(_, "Due Date?", 0, 1),
Transform = Table.TransformColumns(
AddColumn,
{
"Due Date?",
each try AddColumn[maturity date]{_ - 1} otherwise AddColumn[maturity date]{_}
}
),
DueColumn = Table.AddColumn(
Transform,
"Due Date",
each if [maturity date] = [#"Due Date?"] then "N" else "Y"
)
in
DueColumn
}
}
),
Combine = Table.Combine(Group[AllRows])
in
Combine

Sundar Rajagopalan
ThxAlot
Super User
Super User

ThxAlot_0-1760127807161.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



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.

Top Kudoed Authors