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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
heyheyhey
Frequent Visitor

Table with Months as columns - but have Start Date and Finish Date (date range)

Hello,

 

I have a table of requests...

 

Requestor Department Start Date Finish Date

Joe BloggsHR03/10/201606/10/2016
John SmithMarketing13/11/201613/11/2016
Sam BoonFinance27/10/201607/11/2016
Joe BloggsHR19/10/201627/10/2016

 

That I want to summarise in a table in Power BI as something like below (numbers are days). Basically I want it to calculate the duration between each pair of dates, within each month -- excluding weekends.

 

Requestor Department September October November

Joe BloggsHR 11 
John SmithMarketing  35
Sam BoonFinance7  
     

 

Some of the date ranges span multiple months e.g. with Sam, it would need to work out that of the date range (27/10/2016 - 07/11/2016), 3 days are in October and 5 days are in November. 

 

Is something like the above table possible with Power BI??

 

Many thanks 🙂

3 REPLIES 3
ImkeF
Community Champion
Community Champion

You can do this in the query editor like this:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlVwyslPTy9W0lHyCAISBsZ6hgZ6RgaGZiCOGZwTqxOt5JWfkacQnJtZkgGU800syk4tycxLB7INgZoMYZqQOCBNwYm5Ck75+XlAGbfMvMS85FQgy8gc2RZzFA1e+ehuMrREUo2kNTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Name = _t, Department = _t, Start = _t, End = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Department", type text}, {"Start", type date}, {"End", type date}}),
    AddListOfAllDays = Table.AddColumn(#"Changed Type", "AllDays", each {Number.From([Start])..Number.From([End])}),
    #"Expanded AllDays" = Table.ExpandListColumn(AddListOfAllDays, "AllDays"),
    ChangeToDateFormat = Table.TransformColumnTypes(#"Expanded AllDays",{{"AllDays", type date}}),
    AddDayOfWeek = Table.AddColumn(ChangeToDateFormat, "DayOfWeek", each Date.DayOfWeek([AllDays])),
    FilterOutWeekends = Table.SelectRows(AddDayOfWeek, each ([DayOfWeek] <> 5 and [DayOfWeek] <> 6)),
    CalculateMonth = Table.AddColumn(FilterOutWeekends, "Month", each Date.Month([AllDays])),
    #"Removed Columns" = Table.RemoveColumns(CalculateMonth,{"AllDays"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Removed Columns", {{"Month", type text}}, "de-DE"), List.Distinct(Table.TransformColumnTypes(#"Removed Columns", {{"Month", type text}}, "de-DE")[Month]), "Month", "DayOfWeek", List.Count)
in
    #"Pivoted Column"

 

Please let me know if you need help implementing this.

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

Hi ImkeF,


Thanks for your reply! I slightly simplifed the table in my example (it's from a SQL table); I tried to do just the first step (add the custom column AllDays, expand it, and then Close & Apply) and it gave me the following error:

 

DBerror.png

 

Many thanks

ImkeF
Community Champion
Community Champion

Could you please post your query-code from the advanced editor?

Thanks!

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
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 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.