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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Joynul
Frequent Visitor

generating list of months between two dates but the start and end date should include part months

Start Date = 10/01/2022

End Date = 10/08/2022

 

I am looking to create a list where I can show I worked between these two dates, but the start date should still be 10/01/2022 and the end date should be 10/08/2022 all other months in between can be 01/02/2022, 01/03/2022, etc

 

Currently, I have got the code below but this only gives me the correct start date, but not the correct end date, please can you recommend what I can do to show the correct end date as well

 

let
StDt = [Start Date],
EndDt = [END Date],
AllDates = {Number.From([Start Date])..Number.From([END Date])},

StofMonthDates =
List.Distinct (
List.Select(
List.InsertRange(
List.Transform(
AllDates,
each Date.StartOfMonth(Date.From(_))
),
0,
{[Start Date]}
),
each Number.From(_) >= Number.From(StDt)
)
)
in
StofMonthDates

2 ACCEPTED SOLUTIONS
AlexisOlson
Super User
Super User

How about this?

 

 

let
    StDt  = #date(2022,01,10),
    EndDt = #date(2022,08,10),
    Days = Duration.Days(EndDt - StDt),
    AllDates = List.Dates(StDt, Days + 1, #duration(1,0,0,0)),
    SelectDates = List.Select(AllDates, each _ = StDt or _ = EndDt or _ = Date.StartOfMonth(_))
in
    SelectDates

 

Result:

AlexisOlson_0-1661361437898.png

(In m/d/yyyy format)

 

View solution in original post

Hi all,

 

this one does not gerenate a full list of dates between start and end, hence does not need filtering:

let
    StDt  = #date(2022,01,10),
    EndDt = #date(2022,08,10),
    AllDates = List.Generate(()=>StDt, each _ < EndDt, each Date.StartOfMonth(Date.AddMonths(_, 1))) & {EndDt}
in
    AllDates

 

Cheers,

John

View solution in original post

3 REPLIES 3
Joynul
Frequent Visitor

Both solutions work for me, thank you both for your support. I am going to accept the first one as that's the one I used initially 🙂

AlexisOlson
Super User
Super User

How about this?

 

 

let
    StDt  = #date(2022,01,10),
    EndDt = #date(2022,08,10),
    Days = Duration.Days(EndDt - StDt),
    AllDates = List.Dates(StDt, Days + 1, #duration(1,0,0,0)),
    SelectDates = List.Select(AllDates, each _ = StDt or _ = EndDt or _ = Date.StartOfMonth(_))
in
    SelectDates

 

Result:

AlexisOlson_0-1661361437898.png

(In m/d/yyyy format)

 

Hi all,

 

this one does not gerenate a full list of dates between start and end, hence does not need filtering:

let
    StDt  = #date(2022,01,10),
    EndDt = #date(2022,08,10),
    AllDates = List.Generate(()=>StDt, each _ < EndDt, each Date.StartOfMonth(Date.AddMonths(_, 1))) & {EndDt}
in
    AllDates

 

Cheers,

John

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

Top Solution Authors