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
karthik77700
Helper I
Helper I

Dynamically load last three months of data in dataflow

I have a requirement to load dynamically last three months based on max data available in Power Bi Dataflow

 

For example,This is April month but i have max snapshot date as Feb 2029 so i need to load from Dec,Jan and Feb.

 

If March data is loaded dynamically it will load Jan,feb and Mar .

 

 

1 ACCEPTED SOLUTION

Alright. Following the example let me show you how to do it:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCg1W0lEyMjAyMTAyslSK1YlW8nSBiRgaG4JFgt0hIsaGRlARD2+YiKGxgVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [COuntry = _t, Snapshotdate = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"COuntry", type text}, {"Snapshotdate", Int64.Type}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Changed Type",{{"Snapshotdate", type text}}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Changed Type1",{"Snapshotdate", type date}),
    // New Code down here
    var_last3months = Date.AddMonths(List.Max(#"Changed Type2"[Snapshotdate]), -3),
    var_last3calendarmonths = Date.AddMonths(Date.StartOfMonth(List.Max(#"Changed Type2"[Snapshotdate])),-2),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type2", each [Snapshotdate] >= var_last3calendarmonths)
    // New Code finishes here
in
    #"Filtered Rows"

Take a look at the last 3 lines.

I have created two variables that you can choose depending on what you mean with "last 3 months".

  • var_last3months = If you want it to substract 90 days, for example consideran febrary 29th as the last day, then 3 months would be november 29th. Use this variable at the "Filtered Rows" step
  • var_last3monthscalendar = If you want to keep completed months from 1 to last one since current month. Use this one, it will take from December 1st to Febrary 29th.

The Step "Filtered Rows" is the one finally filtering by last 3 months with the variable. You can filter Snapshotdate by the one you have chosen.

I hope that make sense.


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

Happy to help!

LaDataWeb Blog

View solution in original post

5 REPLIES 5
ibarrau
Super User
Super User

Hi, if you can query the source with SQL go with karthik suggestion. Otherwise you can get the date and filter your data with the following power query

Date.AddMonths( [DateFromToSubstractDays] ,-3)

In case you want to get las 3 months from today, you can use "DateTime.FixedLocalNow()" for the date.

Regards,


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

Happy to help!

LaDataWeb Blog

I have created sample data

karthik77700_2-1712935490350.png

 

 

where and how  to apply this formula in M query editor.

My query editor looks like this now,

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCg1W0lEyMjAyMTAyslSK1YlW8nSBiRgaG4JFgt0hIsaGRlARD2+YiKGxgVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [COuntry = _t, Snapshotdate = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"COuntry", type text}, {"Snapshotdate", Int64.Type}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Changed Type",{{"Snapshotdate", type text}}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Changed Type1",{"Snapshotdate", type date})
in
    #"Changed Type2"

 

 

 

Alright. Following the example let me show you how to do it:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCg1W0lEyMjAyMTAyslSK1YlW8nSBiRgaG4JFgt0hIsaGRlARD2+YiKGxgVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [COuntry = _t, Snapshotdate = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"COuntry", type text}, {"Snapshotdate", Int64.Type}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Changed Type",{{"Snapshotdate", type text}}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Changed Type1",{"Snapshotdate", type date}),
    // New Code down here
    var_last3months = Date.AddMonths(List.Max(#"Changed Type2"[Snapshotdate]), -3),
    var_last3calendarmonths = Date.AddMonths(Date.StartOfMonth(List.Max(#"Changed Type2"[Snapshotdate])),-2),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type2", each [Snapshotdate] >= var_last3calendarmonths)
    // New Code finishes here
in
    #"Filtered Rows"

Take a look at the last 3 lines.

I have created two variables that you can choose depending on what you mean with "last 3 months".

  • var_last3months = If you want it to substract 90 days, for example consideran febrary 29th as the last day, then 3 months would be november 29th. Use this variable at the "Filtered Rows" step
  • var_last3monthscalendar = If you want to keep completed months from 1 to last one since current month. Use this one, it will take from December 1st to Febrary 29th.

The Step "Filtered Rows" is the one finally filtering by last 3 months with the variable. You can filter Snapshotdate by the one you have chosen.

I hope that make sense.


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

Happy to help!

LaDataWeb Blog

Thanks for your help .It worked out .

Anonymous
Not applicable

Create a Table/Query (SELECT Date FROM datatable where Date <= (somedate) with all dates needed for Dataflow and Merge the query with this query for Dataflow

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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