Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
I have a table (named Account) that has a created Date.
(This is a simple query to Salesforce objects, accounts table.)
| CreatedDate | Account Name |
| 2/6/2018 2:23:09 AM | Simon |
| 2/4/2019 2:08:18 AM | James |
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?
Solved! Go to 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
Try this (replace 'table' with your table name):
Just noticed your date column has no space so make sure its [createddate] not [created date]. eg:
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
I also tried DAX and that failed, would be good to know what I did wrong here:
You have a simple syntax error. Before the 1 you're missing a comma.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.