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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Convert date to Month & Year to use af filter

Hi, 

 

I've made a calculated column in my Customer table that calculates each customers first day of purchase.

 

I now want to convert that date into a month and year filter, so I for example can filter out customers that was new in August 2016.

 

My first method was to take the calculated colum and then create a secund calculated column with "First Purchase Month = FORMAT(Customer[First Purchase Date];"MMMM YYYY"), which works, but returns a text column that can't be sorted based on dates - Not ideal.

 

Secondly I tried creating a calculated column and then simply change the formating of the column to "mmmm yyyy" in the Modeling tab. But when taking that calculated column into a filter, PowerBI will show the correct text formating, but will show a filter value for each date in the column.

 

How do I create a filter based on the calculated date that I can use as a filter, only showing the distinct months and years?

1 ACCEPTED SOLUTION
v-ljerr-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

My first method was to take the calculated colum and then create a secund calculated column with "First Purchase Month = FORMAT(Customer[First Purchase Date];"MMMM YYYY"), which works, but returns a text column that can't be sorted based on dates - Not ideal.

To sort the "First Purchase Month" column based on dates, you can use the formula below to create a new calculate column called "First Purchase Month Id" first, and then use Sort by Column option under Modeling tab to sort "First Purchase Month" column by "First Purchase Month Id" column. Smiley Happy

First Purchase Month Id =
YEAR ( Customer[First Purchase Date] ) * 100
    + MONTH ( Customer[First Purchase Date] )

sort1.PNG

 

Regards

View solution in original post

1 REPLY 1
v-ljerr-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

My first method was to take the calculated colum and then create a secund calculated column with "First Purchase Month = FORMAT(Customer[First Purchase Date];"MMMM YYYY"), which works, but returns a text column that can't be sorted based on dates - Not ideal.

To sort the "First Purchase Month" column based on dates, you can use the formula below to create a new calculate column called "First Purchase Month Id" first, and then use Sort by Column option under Modeling tab to sort "First Purchase Month" column by "First Purchase Month Id" column. Smiley Happy

First Purchase Month Id =
YEAR ( Customer[First Purchase Date] ) * 100
    + MONTH ( Customer[First Purchase Date] )

sort1.PNG

 

Regards

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors