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
simonGIS
Helper I
Helper I

New Conditional field to check if date field is within last 6 months

I have a table (named Account) that has a created Date. 

(This is a simple query to Salesforce objects, accounts table.)

 

CreatedDateAccount Name
2/6/2018 2:23:09 AMSimon
2/4/2019 2:08:18 AMJames

 

I would like to create a new conditional field that is a true/false value.  Ideally without creating any interim fields.

True: If CreatedDate is within last 6 months

Else False

 

I have been trying a few different IF statements with  DateTime.Date(DateTime.LocalNow() but struggling to get the logic right.  

 

Still taking first steps with PB, and did not find a similar answer in the forum.  Can anyone help me out?

1 ACCEPTED SOLUTION

Ahh, the formula I used is DAX so would work if you were adding a calculated column from Power BI.  To do it in Power Query / M use an M date function like so in the custom column formula:

 

if Date.IsInPreviousNMonths([created date],6) then 1 else 0

 

Also, be mindful of the result you are getting in respect to months elapsed.  For example this function (and the one I provided earlier) will return a 1 for each month boundary that has been crossed, so if the created date is the last day in the month, one month will have elapsed one day later on the first of the next month.  If that is not what you want you might get more precise results by using a calculation based on weeks or days instead

 

if Date.IsInPreviousNWeeks([created date],26) then 1 else 0

 

or

if Date.IsInPreviousNDays([created date],180) then 1 else 0

View solution in original post

6 REPLIES 6
SteveF
New Member

Try this (replace 'table' with your table name):

 

Is Within six months = IF(edate('table'[created date], 6)> today(),1,0)
 

Just noticed your date column has no space so make sure its [createddate] not [created date]. eg:

 

Is Within six months = IF(edate('table'[createddate], 6)> today(),1,0)

Forgive me.  But what is the workflow to get to where you enter that formula.

I entered a custom column from the power query editor, and no cigar

 

Ahh, the formula I used is DAX so would work if you were adding a calculated column from Power BI.  To do it in Power Query / M use an M date function like so in the custom column formula:

 

if Date.IsInPreviousNMonths([created date],6) then 1 else 0

 

Also, be mindful of the result you are getting in respect to months elapsed.  For example this function (and the one I provided earlier) will return a 1 for each month boundary that has been crossed, so if the created date is the last day in the month, one month will have elapsed one day later on the first of the next month.  If that is not what you want you might get more precise results by using a calculation based on weeks or days instead

 

if Date.IsInPreviousNWeeks([created date],26) then 1 else 0

 

or

if Date.IsInPreviousNDays([created date],180) then 1 else 0

= Table.AddColumn(#"Removed Columns1", "NewClientLastYear", each if Date.IsInPreviousNWeeks([CreatedDate],26) then 1 else 0)
 
I get a warning shown:
1.jpg

1.jpg

1.jpg

1.jpg

 

I also tried DAX and that failed, would be good to know what I did wrong here:

1.jpg

You have a simple syntax error. Before the 1 you're missing a comma.

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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
Top Kudoed Authors