Renaming Columns with Dates as MMMM/YYYY

programsam

Board Regular
Joined
Feb 10, 2016
Messages
123
Looking to rename columns with dates in them as the MonthName and Year only using PQ. Not every column has a date so it would have to parse the list of column headers, find the one's with dates (all the first day of the month - '1/1/2023', '2/1/2023', etc.). The best I've done thus far has returned the month name but it does not display the year, it only shows the formatting for the year ("YYYY").

For clarity, the columns look like this.
1689248193034.png


What I'm wanting is: "July 2022"

What I'm getting using the code below is "July YYYY"

Excel Formula:
= Table.TransformColumnNames((#"Renamed Columns1"),each try Date.FromText(Table.ColumnNames((#"Renamed Columns1"){n}), otherwise _))
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
You need to use yyyy not YYYY in the format code (which isn't in the M code you posted). ;)
 
Upvote 0
You need to use yyyy not YYYY in the format code (which isn't in the M code you posted). ;)
OMG, apologize for that... copied the wrong (and incorrect) code. This is what I came up with and changing the "YYYY" to "yyyy" fixed the issue. Thank you!

Excel Formula:
= Table.TransformColumnNames(#"Promoted Headers", each try Date.ToText(Date.From(_),"MMMM/yyyy") otherwise _)
 
Upvote 0

Forum statistics

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