Adding days to a date using M...

Matty

Well-known Member
Joined
Feb 17, 2007
Messages
3,717
Hi Team,

Is there a way to update an existing date column in Power Query by means of adding or subtracting days?

I can use the function Date.AddDays to create a new column to do this, but it'd be neater to change the existing column rather than having to create a new one.

I've had a look around for ways of doing this, but I can't find anything obvious.

Cheers,

Matty
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
You can subtract days using the filter function, but as far as adding dates... the source data is the data. PowerQuery doesn't add data (rows) to columns it pulls, only to those it creates.
 
Upvote 0
You can subtract days using the filter function, but as far as adding dates... the source data is the data. PowerQuery doesn't add data (rows) to columns it pulls, only to those it creates.

Thanks. I just wanted to make sure I wasn't adding steps to the script that weren't needed.

Cheers,

Matty
 
Upvote 0
This looks like a misunderstanding.

You can select your date column, choose one of the transform options for date (e.g. start of month) and then adjust the generated code to something like:
Code:
= Table.TransformColumns(Source,{{"Date", [B]each Date.AddDays(_,3)[/B], type date}})
 
Upvote 0
Thanks Marcel - that neatens up my script and avoids a lot of unnecessary steps!

Cheers,

Matty
 
Upvote 0
This looks like a misunderstanding.

You can select your date column, choose one of the transform options for date (e.g. start of month) and then adjust the generated code to something like:
Code:
= Table.TransformColumns(Source,{{"Date", [B]each Date.AddDays(_,3)[/B], type date}})


You have several of these questions answers throughout the internet... however, you only specify how to ADD to the date... I am hoping to figure out how to subtract one day from the date.

I am trying to write a TRUE/FALSE that lets me know if the date was yesterday.

Closest I can think of

I'm an idiot...

Date.IsInPreviousDay

UGH!

=Date.IsInCurrentDay[Date] - 1 but I don't know how to write the "-1" to M can understand what I'm trying to do.
 
Last edited:
Upvote 0
You can use the code from Sphinx404 to subtract simply by setting a negative number.

Code:
= Table.TransformColumns(Source,{{"Date", [B]each Date.AddDays(_,[COLOR=#ff0000]-3[/COLOR])[/B], type date}})
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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