Rounding a date to month and year

nroy

Board Regular
Joined
Oct 16, 2007
Messages
121
Hi,

I'm trying to group some dates by month in a pivot table but I'm getting a message saying 'cannot group that selection'.

I'm trying to do it another way. I want to add another column to my data which will convert the full date to month and year. I've tried =TEXT(H2,"mmm-yyyy") which works but as it's text I can't sort in month order.

Does anyone know a formula that will remove the day but still recognise it as a date and allow me to sort the data in decending order?

Thanks
Nicola
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
=TEXT(H2,"mmm-yyyy") works fine for me.

What is in H2 exactly? Is this stored as a date or text?
 
Upvote 0
=TEXT(H2,"mmm-yyyy")

is exactly what it says it is, TEXT, dates are numbers, so it means that you no longer have a valid date, and trying to sort them would set the order

Apr,Aug,Dec,Feb,Jan,Jul,Jun,Mar,May,Nov,Oct,Sep

however, =--TEXT(H2,"mmm-yyyy")

would default the dates to the 1st of the month, which is a valid date, allowing you to sort correctly.
 
Upvote 0
=TEXT(H2,"mmm-yyyy")

is exactly what it says it is, TEXT, dates are numbers, so it means that you no longer have a valid date, and trying to sort them would set the order

Apr,Aug,Dec,Feb,Jan,Jul,Jun,Mar,May,Nov,Oct,Sep

however, =--TEXT(H2,"mmm-yyyy")

would default the dates to the 1st of the month, which is a valid date, allowing you to sort correctly.

That's what I thought, but I just used =TEXT(H2,"mmmm-yyyy") and it sorted it Jan - Dec...
 
Upvote 0
That's what I thought, but I just used =TEXT(H2,"mmmm-yyyy") and it sorted it Jan - Dec...

Looking into it a little more, it appears it would depend how you sort (version of excel, or option settings may also have some effect).

For me (using excel 07), the standard sort was listing months alphabetically, but advanced sort, treat text that looks like a number as a number, sorted the months chronologically.
 
Upvote 0

Forum statistics

Threads
1,224,559
Messages
6,179,513
Members
452,921
Latest member
BBQKING

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