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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Extract month and year from date

Hi, 

 

I'm trying to do a report that tracks completed actions in months over the past 2 years. Therefore I need to extract the month and year from a date into a new column. I have tried the month and year functions but then they are saved as text when I concatenate so can't sort them properly in a graph. 

 

Any ideas would be helpful.

 

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous 

Did you use format function to build extract month and year?

If you use format "YYYY" and format "MM", "YYYYMM",your result will show text type.

Power Query:

Select Date column and click Date in Add column.

1.png

Then add a custom column and change it type to whole number.

2.png

Dax:

In addition to  

Dax_YearMonth = YEAR('Table'[Date])*100+MONTH('Table'[Date])

Result is as below.

3.png

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous 

Did you use format function to build extract month and year?

If you use format "YYYY" and format "MM", "YYYYMM",your result will show text type.

Power Query:

Select Date column and click Date in Add column.

1.png

Then add a custom column and change it type to whole number.

2.png

Dax:

In addition to  

Dax_YearMonth = YEAR('Table'[Date])*100+MONTH('Table'[Date])

Result is as below.

3.png

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

BA_Pete
Super User
Super User

Hi @Anonymous ,

 

For anything date-related, you should set up a separate calendar dimension table and relate this to your fact table.

In DAX, this can be as easy as creating a new table as follows:

dimCalendar = CALENDARAUTO()

 

Once you have your list of dates, then create new columns with your MONTH() and YEAR() functions from the date.

Concatenate these into another new column which is just the [Year] and [Month] numerical values together, like 202005, 202006 etc. Format this as a number.

Create any other time formats that you want, such as 'monthYearText' (Apr-20 etc.), then select your text formatted version of the date, go to Sort by column on the ribbon, then select your numerical version column to sort the text version by.

Relate your dimCalendar table on [Date] to your fact table data field.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.