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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Inacio11
Frequent Visitor

List dates between two dates

Hi all,

I'm looking for a formula to list dates between 2 dates. Suppose I have the following example:

Column A) InitialDate: 19/07/2019

Column B) EndDate: 19/10/2019

so, I would like to get as result.....19/07/19, 19/08/19, 19/09/19 and 19/10/19 (one occurrence per month dd/mm/yy)

I'm using the formula: {Number.From([InitiaDate])..Number.From([EndDate)]}  but I getting as results all dates , such us 19/07/2019, 20/07/2019, 21/07/2019....till 19/10/2019. HowCould I solve this issue ?

Thanks in advance 

Jeferson

1 ACCEPTED SOLUTION

Hi @Inacio11 

you don't use it as a function. Then the "each" isn't ambigous any more.

Try this for result instead:

Result = List.Transform({0..NoOfIntervals}, (x) => Date.AddMonths([FROM], x))

 

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

4 REPLIES 4
Inacio11
Frequent Visitor

Hi Imke,

It worked ! Thanks vey much !

I just did a small adjustment as follow:

= List.Transform({0.."number of events displayed at the sheet -1"}, (x) => Date.AddMonths([FROM], x))

 

Regards,

Inacio11

Inacio11
Frequent Visitor

Hi,

I thankful with the early repply, however I'm still facing errors. Please check the screeshots for more details.

Screen1 

Screen2 

 

Thanks in advance

Inacio11

Hi @Inacio11 

you don't use it as a function. Then the "each" isn't ambigous any more.

Try this for result instead:

Result = List.Transform({0..NoOfIntervals}, (x) => Date.AddMonths([FROM], x))

 

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

ImkeF
Super User
Super User

Hi @Inacio11 

this function should get you there:

 

(From as date, To as date) =>
let
    NoOfIntervals = (Date.Year(To)*12+Date.Month(To))-(Date.Year(From)*12+Date.Month(From)),
    Result = List.Transform({0..NoOfIntervals}, each Date.AddMonths(From, _))
in
    Result

 

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors