In Power Query based on contract dates assign number of days per month

Wishmaster40

New Member
Joined
Dec 18, 2023
Messages
12
Office Version
  1. 2021
Platform
  1. Windows
  2. MacOS
Dear All,

I previously made a post, for the same issue but in Excel. See the link below:

Validate month based on contract dates & Calculate number of weeks in that month to calculate hours booked per month

Now i would like to achieve the same but in Power Query, from a API i get the following data back.

1706790824113.png


And i want to create additional columns in Power Query for the number of days per month.

In Excel this was achieve by formula's not created by myself Felix and 2 other persons, and i really appreciate there help a lot!!

Formula1

1706791002230.png

Formula2
1706791034315.png

Formula3
1706791075639.png


How can i convert one of these formula from above into M code for Power Query?
1706791306988.png


Of course i understand that i have to create a column for Jan/24, Feb/24 etc and most likely hard code each month into the column or somebody her should know a better solution.

Who can help me out with this?

Many thanks!!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Luckily, getting the number of days in a month is pretty simple with the Date.DaysInMonth function. Have a look here: Date.DaysInMonth - PowerQuery M
Thank you for your reply, but i wasn't able to reproduce the same as in Excel with just this formula.

This video, is very helpful however i get a table of all the dates and i just want an extra column.


List.Generate(
()=> [fDate = pStart, fDay= Date.DaysInMonth(fDate)-Date.Day(fDate)+1],
each [fDate] <= pEnd,
each
let EoM = Date.EndOfMonth( Date.AddMonths([fDate],1)) in
if EoM > pEnd then
[fDate= Date.AddDays(Date.EndOfMonth([fDate]), Date.Day(pEnd)) , fDay= Date.Day(fDate)]
else
[fDate= EoM , fDay = Date.Day(fDate)]

1706870599308.png


This is what i am looking for just per column the days.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top