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

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

Reply
smeg
Helper I
Helper I

Hekp with M Query

Hi,

     I am trying to retrieve  data into one of the query in power query editor  using M for  last 18 months,but below query retrieves 2 years of data.

Can you please let me know the formula to just retrieve last 18 months that is data from 06012022.

dbo_v_Ns_Metrics_1 = Table.SelectRows(dbo_v_Ns_Metrics, each [PE_Date_Int] > ((Date.Year(Date.AddDays(DateTime.LocalNow(), -1 )) - 2) * 10000) + 1231),

 

Thanks..

1 ACCEPTED SOLUTION

Below query  worked for me as per my requirement,to retrieve  data for  last 18 months,

As I also  need a number format not a date format.

smeg_0-1702488521424.png

 

View solution in original post

4 REPLIES 4
Daryl-Lynch-Bzy
Community Champion
Community Champion

Hi @smeg - if you enter the following function the result is 20211231:

= (((Date.Year(Date.AddDays(DateTime.LocalNow(), -1 )) - 2) * 10000) + 1231)

// 20221231

 This result is number, not a date.  

 

Could you use the following function instead.

= Date.AddMonths( Date.StartOfMonth( DateTime.LocalNow() ) , -18)

// 01/06/2022 00:00:00

Another thing to consider is the Data Type of the [PE_Date_Int] column.  Is it Date?  The example "06012022" suggest that it might be Text.

Hi 

Data Type of the [PE_Date_Int] column is integer(number)  not a date,How can i cast/convert below function accordingly because when i use below one the data refresh is taking forever,because of comparison between number and date.

= Date.AddMonths( Date.StartOfMonth( DateTime.LocalNow() ) , -18)

 

Thanks..

= Number.From(Date.ToText(Date.AddMonths( Date.StartOfMonth( DateTime.LocalNow() ) , -18),"yyyyMMdd"))

Below query  worked for me as per my requirement,to retrieve  data for  last 18 months,

As I also  need a number format not a date format.

smeg_0-1702488521424.png

 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.