cancel
Showing results for
Did you mean:

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

New Member

## Extract Month and Year from DateTime field to get MMM-YY

I am trying to end up with a column that contains the month and year of a DateTime field.

I can find how to extract the month from a date or extract the year but I cannot find how to extract the month and year into one field.

2 ACCEPTED SOLUTIONS
Super User

= MONTH([date] & YEAR([date])

Or, the long way:

CONCATENATE(MONTH([date]),YEAR([date]))

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Resident Rockstar

And wrap the whole thing in VALUE() to cast back to a numeric type if you need:

= VALUE( MONTH( [Date] ) & YEAR( [Date] ) )
18 REPLIES 18
Frequent Visitor

What if I have

is the case and we need to sort using the month, meaning all the vlaues from each month, if I am not wrong , I need to create a measure for that but could anyone guide me a bit on this , how I will do it  ?

Super User

= MONTH([date] & YEAR([date])

Or, the long way:

CONCATENATE(MONTH([date]),YEAR([date]))

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

This works when you extract Year and Monthnumber like 20141, 20142,20143....201412...but if I want to get 2014 Jan, 2014 Feb, 2014 Mar and so...

this forumula works better when you extract monthnumber and yr, Any thoughts on that what I mentioned above.

Thanks,

Resident Rockstar

And wrap the whole thing in VALUE() to cast back to a numeric type if you need:

= VALUE( MONTH( [Date] ) & YEAR( [Date] ) )
Employee

I tried using formula to create custom column (format "MM-YY) from existing date field (Date 2)  in POWER BI desktop however seems it got set up as measure (see attached).

Super User

Hi,

That should be a DAX formula.  Click on the Data Tab in the black bar on the left hand side and then click on Calculated column formula.  Write this formula in the relevant table

=FORMAT([Date 2],"mmmm")

Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com
Employee

Hi Ashish, BIG Thanks for the help. This worked.

One additional challenge i faced is that resultant measure from formula suggested is set up as "Text" field.  I am not able to sort the chart based on calendar months.

Thanks again for guidance and help !!

Super User

Hi,

Regards,
Ashish Mathur
http://www.ashishmathur.com
Regular Visitor

My DateKey looks like this   5/7/2007 12:00:00 AM  and so on.  How do I extract just the month and the year?  I'd like to leave the original column alone and put the new date (month and year) into a new column.  Any help is appreciated.  Thanks!

Karen

Super User

Hi,

Try this

=FORMAT(Data[Date],"mmm-yyyy")

Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com
New Member

Hi Ashish

How can sort by Jan-2019-Dec-2019 instead of date?

Thanks

Sameer

Frequent Visitor

Hello Guys,
The process is quite simple.
Create a New Column as:

Modified Date = FORMAT('table name'[date column], "yyyy mm dd")

Jan 2019 -> 2019 01 01

Feb 2019 -> 2019 02 01

.

.

Dec 2019 -> 2019 12 01

Now build your visualization and use the sort option to sort it using the Modified Date column in ascending
Hope this helps.
Let me know if you need anything else.

Frequent Visitor

I have three months: Feb, Mar, Apr but its showing in alphabetical order: Apr, Feb & Mar

How shall I resolve this issue?

@Ashish_Mathur wrote:

Hi,

Try this

=FORMAT(Data[Date],"mmm-yyyy")

Hope this helps.

Super User

Hi,

See my post data 6 MArch 2019.  I have shared a link there.

Regards,
Ashish Mathur
http://www.ashishmathur.com
New Member

This does not work on Direct Query model

New Member

I tried doing that but the data got sorted in descending order, meaning, whichever months had higher sales appeared first. I would like to sort the data by month.

Regular Visitor

yes, that worked.  Thank you!

Super User

Hi,

Regards,
Ashish Mathur
http://www.ashishmathur.com

Announcements

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

#### Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

#### Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors