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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Create a column with fixed values based on current month

Hello, I am pretty new to power query and I am trying to add a column that is filled as "01/MM/YYYY" for every row. Based on a check of the current date. I.e today is 20/01/2021 so the column would be filled with "01/01/2020" for all the rows.

 

I found the option to add a custom column however I dont know what to put in the code to give me what I want.

 

 

And next I would like to fill another column but considering the past year, using the same example, today being 20/01/2021 I want the column to be filled with "01/01/2020" so, subtracting a year from current date.

 

Any clues how to do so ?

2 ACCEPTED SOLUTIONS
artemus
Microsoft Employee
Microsoft Employee

You can use the the below function. Replace Date with DateTime or DateTimeZone depending on the column type.

Date.ToText([DateColumn], "01/MM/yyyy")

View solution in original post

AlB
Community Champion
Community Champion

Hi @Anonymous 

For the first colum:

 = Date.StartOfYear(Date.From(DateTime.LocalNow()))

 For the second:

Date.AddYears([Column1], -1)

Note it references Column1, the first column we've created

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

5 REPLIES 5
AlB
Community Champion
Community Champion

@Anonymous 

1st column: reads the current Date and time, converts it to date and extracts the first day of the year the date is in

2nd column simply takes the date from the previous column and subtracts one year

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Cheers 

 

SU18_powerbi_badge

Anonymous
Not applicable

Got it, thank you !

 

AlB
Community Champion
Community Champion

Hi @Anonymous 

For the first colum:

 = Date.StartOfYear(Date.From(DateTime.LocalNow()))

 For the second:

Date.AddYears([Column1], -1)

Note it references Column1, the first column we've created

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Anonymous
Not applicable

That worked !, thank you. Can you help me understand what that fuction does ? the second column is pretty straight foward however I stil can´t grasp the first one.

artemus
Microsoft Employee
Microsoft Employee

You can use the the below function. Replace Date with DateTime or DateTimeZone depending on the column type.

Date.ToText([DateColumn], "01/MM/yyyy")

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors