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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

How to split a Date Range into months

Hi,

I have a data set with "Valid From" and "Valid To" dates which shows the price of a material. The date range is from 7/1/2016 to 10/31/2016. Is there any way to split the date range into 3 separate months? 

  • 7/1/2016 to 8/1/2016
  • 8/1/2016 to 9/1/2016
  • 9/1/2016 to 10/1/2016

split.PNG

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

Based on your description, I created data to reproduce your scenario.

You may click ‘Edit Query’, go to Query Editor, choose ‘Add Column’.

New Valid From = let

IsCrossMonth = Date.Month([Valid to])<>Date.Month([Valid From]) or Date.Year([Valid to])<>Date.Year([Valid From]),

MonthDu =  (Date.Year([Valid to])-Date.Year([Valid From]))*12 +Date.Month([Valid to]) -Date.Month([Valid From])

in

List.Generate(()=> [ x = 0 , y = [Valid From]],each [x] <= MonthDu, each [y = [y],x =[x]+ 1],each if[x]=0 then [y] else Date.AddDays(Date.AddMonths([y],[x]),1-Date.Day([y])))

 

Secondly, you can click the ‘New Valid From’ column and choose ‘Expand to new rows’.

 

Thirdly, you can add a custom column as follows.

New Valid To = if[Valid From] = [New Valid From]

then if (Date.Year([Valid to])-Date.Year([Valid From]))*12 +Date.Month([Valid to]) -Date.Month([Valid From])<1

    then [Valid to]

    else Date.AddDays(Date.AddMonths([New Valid From],1),-1)

else if (Date.Year([Valid to])-Date.Year([New Valid From]))*12 +Date.Month([Valid to]) -Date.Month([New Valid From])<1

    then [Valid to]

    else

Date.AddDays(Date.AddMonths([New Valid From],1),-1)

 

Finally, you can remove ‘Valid From’ and ‘Valid To’ columns.

Result:

x5.png

If I misunderstand your thought, please show me your sample data and expected output. I am glad to solve the problem for you. Here is my pbix .

 

Best Regards,

Allan

 

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

View solution in original post

3 REPLIES 3
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

Based on your description, I created data to reproduce your scenario.

You may click ‘Edit Query’, go to Query Editor, choose ‘Add Column’.

New Valid From = let

IsCrossMonth = Date.Month([Valid to])<>Date.Month([Valid From]) or Date.Year([Valid to])<>Date.Year([Valid From]),

MonthDu =  (Date.Year([Valid to])-Date.Year([Valid From]))*12 +Date.Month([Valid to]) -Date.Month([Valid From])

in

List.Generate(()=> [ x = 0 , y = [Valid From]],each [x] <= MonthDu, each [y = [y],x =[x]+ 1],each if[x]=0 then [y] else Date.AddDays(Date.AddMonths([y],[x]),1-Date.Day([y])))

 

Secondly, you can click the ‘New Valid From’ column and choose ‘Expand to new rows’.

 

Thirdly, you can add a custom column as follows.

New Valid To = if[Valid From] = [New Valid From]

then if (Date.Year([Valid to])-Date.Year([Valid From]))*12 +Date.Month([Valid to]) -Date.Month([Valid From])<1

    then [Valid to]

    else Date.AddDays(Date.AddMonths([New Valid From],1),-1)

else if (Date.Year([Valid to])-Date.Year([New Valid From]))*12 +Date.Month([Valid to]) -Date.Month([New Valid From])<1

    then [Valid to]

    else

Date.AddDays(Date.AddMonths([New Valid From],1),-1)

 

Finally, you can remove ‘Valid From’ and ‘Valid To’ columns.

Result:

x5.png

If I misunderstand your thought, please show me your sample data and expected output. I am glad to solve the problem for you. Here is my pbix .

 

Best Regards,

Allan

 

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

Great solution @v-alq-msft .

 

But the only problem is whenever we give a start date other than the first day of month ,

the first row will have an end date in the next month

 

Prudhvi_BSS_1-1594133043849.png

 

Is there a way we can correct it, so that even the first row is up to the end of first month?

I need this too.

Please help us!

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
Top Kudoed Authors