Problem with calculated dates

SDowse

Board Regular
Joined
Sep 23, 2009
Messages
120
Hi,

I have the below step in Power Query:

#"Added Custom3" = Table.AddColumn(#"Changed Type4", "RF Collection Day", each if #date((Date.Year(DateTime.LocalNow())),(Date.Month(DateTime.LocalNow())),[RF.dd_collection_day]) <= Date.From(DateTime.LocalNow()) then #date((Date.Year(DateTime.LocalNow())),(Date.Month(DateTime.LocalNow())+1),[RF.dd_collection_day]) else #date((Date.Year(DateTime.LocalNow())),(Date.Month(DateTime.LocalNow())),[RF.dd_collection_day])),

This has been working fine, until today. The 31st of a month where the following month doesn't have 31 days. What the above is meant to do is:
if the year today, month today and RF.dd_collection_day is less than or equal to today, then add 1 month

But today, that creates the date 31st September 2023, which doesn't exist.

How do I update the step so that where the calculated date is greater than number of days in the relevant month, move the date to the 1st of the following month?
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,224,816
Messages
6,181,139
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