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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
madlfc87
Helper I
Helper I

Calculate number of days between two days and put in respective months

Hi everyone,

 

I'm having difficulties calculating the number of days between two dates because I need the days to be counted for each seperate month. For example if the two dates are in the same month then it's easy.

 

Table.AddColumn(Source, "Subtraction", each Duration.Days([EndDate] - [StartDate])+1, Int64.Type)

 

But when the dates are in different months i need to calculate the days that fall in each month seperately. 

 

Please see below a part of the two date columns 

 

madlfc87_0-1726556400083.png

Thank you for your help!

3 REPLIES 3
bhanu_gautam
Super User
Super User

@madlfc87 , Try using below m code

 

let
Source = ... , // Your data source
AddDateList = Table.AddColumn(Source, "DateList", each List.Dates([StartDate], Duration.Days([EndDate] - [StartDate]) + 1, #duration(1, 0, 0, 0))),
ExpandDateList = Table.ExpandListColumn(AddDateList, "DateList"),
AddYearMonth = Table.AddColumn(ExpandDateList, "YearMonth", each Date.Year([DateList]) * 100 + Date.Month([DateList]), Int64.Type),
GroupByYearMonth = Table.Group(AddYearMonth, {"YearMonth"}, {{"DaysInMonth", each Table.RowCount(_), Int64.Type}})
in
GroupByYearMonth




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






I will need to create this visualization so i would need a table with month, year, location, days 

 

madlfc87_0-1726560235627.png

 

https://drive.google.com/file/d/1mY3Sh23MGMPULASau0uYKayL4OUwR10i/view?usp=drive_link

 

This is the file. Could you assist me? I didn't fully understand your code. If you want I will give you access. Thank you

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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