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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Honne2021
Helper II
Helper II

PowerBi or Power Query Formula for dates before previous date

The Effective End Date is being done manually which is grueling cause there are so many dates in our file now. Is there a dax formula or m code that I can use to get the Effective End Date? The effective end date is the day before the new effective date (not sure if I explained that well enough but here's a picture). 

Question.png

Thank you in advance! 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Honne2021 ,

 

Got it. In this case for quick implementation, I'd suggest you use DAX:

Effective End Date(DAX) = 
var _next= CALCULATE(MAX('Table'[Effective Date]),FILTER('Table',[Store]=EARLIER('Table'[Store])&& [Index]=EARLIER('Table'[Index])+1))
return IF(_next=BLANK(),BLANK(), _next-1)

Best Regards,
Eyelyn Qin

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @Honne2021 ,

 

Got it. In this case for quick implementation, I'd suggest you use DAX:

Effective End Date(DAX) = 
var _next= CALCULATE(MAX('Table'[Effective Date]),FILTER('Table',[Store]=EARLIER('Table'[Store])&& [Index]=EARLIER('Table'[Index])+1))
return IF(_next=BLANK(),BLANK(), _next-1)

Best Regards,
Eyelyn Qin

Thank you very much!

Anonymous
Not applicable

Hi @Honne2021 ,

 

According to this—— Is there a dax formula or m code that I can use to get the Effective End Date? 

 

I have done it in this two ways, and both need an index column in Power Query.

Eyelyn9_0-1649124576479.png

 

1.Whole M syntax:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwNNU31TdTitUBc8z0LfQNERxDAwTPQt9M38hUKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Effective Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Effective Date", type date}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Next Row", each try #"Added Index" [Effective Date]{ [Index] }otherwise null),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Effective End Date(M)", each Date.AddDays([Next Row] ,-1)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Next Row"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Effective End Date(M)", type date}})
in
    #"Changed Type1"

2. Using DAX to create a column:

Effective End Date(DAX) = 
var _next= CALCULATE(MAX('Table'[Effective Date]),FILTER('Table',[Index]=EARLIER('Table'[Index])+1))
return IF(_next=BLANK(),BLANK(), _next-1)

Final output:

Eyelyn9_2-1649124978532.png

 

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

Hi, sorry I forgot to mention that the column can refer to different stores. The Effective End Date should be specific to the particular store only and not the entire Effective Date column. 
 

Qs2.png

Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Right way would be to import the file in PQ through Excel - Advanced Editor and delete everything after Source and copy everything after source from here.  (Make sure comma is there at the end Source statement). Hence, in Excel this would become like this (so you need to change only Table1 here)

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Effective End Date", type date}}),
    #"Get Effective Date" = Table.FromColumns(Table.ToColumns(#"Changed Type") & {{null} & List.RemoveLastN(#"Changed Type"[Effective End Date],1)},Table.ColumnNames(#"Changed Type")&{"Effective Date"})
in
    #"Get Effective Date"

 

Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately)

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc2xDcAgDATAXVxHet5YOMxisf8awVBAyqsuQhyV0MIm4wnpqOWoQS31LlGhP5GHBk/0BYfd2MHU+AA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Effective End Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Effective End Date", type date}}),
    #"Get Effective Date" = Table.FromColumns(Table.ToColumns(#"Changed Type") & {{null} & List.RemoveLastN(#"Changed Type"[Effective End Date],1)},Table.ColumnNames(#"Changed Type")&{"Effective Date"})
in
    #"Get Effective Date"

If it is an excel file, should I still keep the "Compression.Deflate" code?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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 Solution Authors