Home » Power Query M Functions » Date.AddDays – Power Query M Function

Date.AddDays – Power Query M Function

Date Add Days M Function

In Power BI’s M Language, you can use the Date.AddDays function to add or subtract a specified number of days from a given date.

Let’s get stated-

Download the sample Dataset from below link-

Now follow these steps-

Step-1: Open Power Query Editor by selecting “Transform data” in the Home tab of Power BI Desktop.

Transform Data

Transform Data

Step-2: In the Queries pane,  select the “Orders” table.

Step-3: In the Home tab, click on “Add Column”  and choose “Custom Column”.

Select Query in Query Editor

Select Query in Query Editor

Step-4: In the “Custom Column” dialog box, provide a name for the new column, exp- “NewOrderDate”.



Step-5: In the “Custom column formula” box, enter the following expression, and click on “OK” to create the new column.

Date.AddDays([Order Date], 7)
Date Add Days M Function

Date Add Days M Function

After applying the changes, you will see a new column named “NewOrderDate” in the “Orders” table, which contains the order date plus 7 days for each row.

How to subtract 7 days from “Order date”? See the expression below:

Date.AddDays([Order Date], -7)

See the final output

Date Add Days Output

Date Add Days Output



 

Leave a Reply