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

IF then statement and extracting date together

Hi,

 

I have a data set where one ofthe columns is created_date(mm/dd/yyyy). I want to create another column where if the created_date is before 04/10 it populates "Historic" otherwise it populates the month and year from the created_date column. 

 

Is it possible to do it? 

Any help on this is much appreciated.

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

You are creating a column in Power Query while the above code is in DAX, this is the reson you are getting the error RightParen expected.

 

1.jpg

 

Incase you want to do it in M Language or Power Query

 

Column = if [Date] < #date(2020, 4, 20) then "Historic" else (Date.MonthName([Date]) & " " & Text.From(Date.Year([Date]))))

 

 

2.JPG

 

Replace [Date] --> with Created_Date

 

 

 

 In DAX

 

Column = IF(Dates[Date] < DATE(2020,04,10),"Historic", FORMAT(Dates[Date],"mm/yyyy"))
 
 
3.JPG
 
replace Dates --> with your table name
replace [Date] --> with your column name
 
 
Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

 

 

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous , Create a new column like

if([Created_date] < date(2020,04,10),"Historic" format([Created_date],"mm/yyyy"))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thanks for your response! However, this doesnt seem to work . It shows an error RightParen expected.

Anonymous
Not applicable

HI @Anonymous 

Us teh below code 

IF(table([CREATED_DATE])<DATE(2020,04,10),"Historic", FORMAT([CREATED_DATE],"MM/YYYY"))

Hi @Anonymous ,

 

You are creating a column in Power Query while the above code is in DAX, this is the reson you are getting the error RightParen expected.

 

1.jpg

 

Incase you want to do it in M Language or Power Query

 

Column = if [Date] < #date(2020, 4, 20) then "Historic" else (Date.MonthName([Date]) & " " & Text.From(Date.Year([Date]))))

 

 

2.JPG

 

Replace [Date] --> with Created_Date

 

 

 

 In DAX

 

Column = IF(Dates[Date] < DATE(2020,04,10),"Historic", FORMAT(Dates[Date],"mm/yyyy"))
 
 
3.JPG
 
replace Dates --> with your table name
replace [Date] --> with your column name
 
 
Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

 

 

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.