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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
curtismob
Helper IV
Helper IV

DATEADD Does not work for date 6 months prior, returns blank

I am trying to calculate the date six months prior to current date, but it does not work.  I created a calculated column as shown below, but blanks are returned.  I have verified that 'Date Time'[Current Date] is current date. 

 

Date Six Mos Prev = DATEADD('Date Time'[Current Date], -6, MONTH)

 

'Date Six Mos Prev' and 'Date Time'[Current Date] are both defined with a 'Date' data type and format of (yyyy-MM-dd)

 

 

5 REPLIES 5
bblais
Resolver III
Resolver III

This only works if the corresponding date from 6 months ago is actually in your 'Date Time' table, so it probably is working for dates greater than your earliest date + 6 months.

 

If it were me, I would do this in the query for the 'Date Time' table and not in a DAX column.  If you edit your query and add a custom column with the following formula it should give you want you want:

 

= Date.AddMonths([Current Date],-6)

Hi @bblais,

 

Thank you for the quick response. 

 

My 'DateTime' table actually has date information from 5 years previous through current year and I verified 10/12/2016 (six months prior to today) is in the 'DateTime' table.

 

I am actually trying to create a true/false for dates w/in the last six months to be used in a Visual filter.

 

I don't have much experience with making query changes, I would rather use DAX, if possible.  If the query change is my only choice, I will also need to create and name the new column, correct?

 

Thank you,

@curtimob

Hi @curtismob,

 

If "DATEADD" not works on your side, you can try to use below formula:

 

Prev6Month = DATE([date].[Year],[date].[MonthNo]-6,[date].[Day] )

 

In addition, I'd like to suggest you to check your date column before these operation. If you date field not the date type, you should transform it first.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

@v-shex-msft, I respectfully disagree with your solution as it would give an error/invalid date for any day before July 1st of any year.

 

@curtismob, you could try this in your date table to get a bit of 1 for any date in the last 6 months:

 

isInLast6Months = IF('Date Time'[Current Date] < TODAY(),IF(DATEDIFF('Date Time'[Current Date],TODAY(),MONTH) <= 6,1,0),0)

The first IF is just to handle future dates as the DATEDIFF function doesn't like it when the start date is after the end date.

 

 

Below is what I finally came up with to get the day 1 of the month six months prior.  

 

I know the 'Date Time'[Current Date].[Day]-'Date Time'[Current Date].[Day] +1 seems redundant, but it seems like I was getting an error if I just entered a 1.

 

Date 6 Mos Prior Day 1 =

DATE

(

'Date Time'[Current Date].[Year],

'Date Time'[Current Date].[MonthNo] - 5,

'Date Time'[Current Date].[Day]-'Date Time'[Current Date].[Day] +1

)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors