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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

DATEADD function does not work well with filter.

Hi all,

 

I have a requirement calculate the data last some days period. I explored and used function DATEADD.

I also have some filter in my data, after applied, I assumed it worked well either with filter or not.

But when I have test with filter, the measure with DATEADD seemed like didnot change.

 

Does anyone can explain or give me a solution of this?

Thank you.

3 ACCEPTED SOLUTIONS
az38
Community Champion
Community Champion

Hi @Anonymous 

dateadd() is a very tricky function

according https://docs.microsoft.com/en-us/dax/dateadd-function-dax

The result table includes only dates that exist in the dates column.

If the dates in the current context do not form a contiguous interval, the function returns an error.

so, if your data model doesnt ensure continious of dates it's better to use statements like 

Table[Date] + 90

or to create a Calendar Table for more complicated calculations

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

amitchandak
Super User
Super User

@Anonymous , as explained by @az38 you can not use dateadd. He also suggested solution. You can also create a date add like this

 

New Date = date(year(table[date])+0,month(table[date])+0,day(table[date])+0)

+0 is what you have replace in year , month or date

To add 7 days

New Date = date(year(table[date]),month(table[date]),day(table[date])+7)

To add 7 Months

New Date = date(year(table[date]),month(table[date])+7,day(table[date]))

You can add more than 12 month too

 

View solution in original post

v-xuding-msft
Community Support
Community Support

Hi @Anonymous ,

I add a few blogs and videos that you could reference to learn more about the function of DATEADD.

Using DATEADD() and other Date Tips for Filtering Data in Power BI 

The DATEADD Function: The Best And Most Versatile Time Intelligence Function in Power BI 

DATEADD function (DAX) - DAX DATEADD function In Power BI Desktop 

DAX Fridays #16: DATEADD 

 

Best Regards,

Xue Ding

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-xuding-msft
Community Support
Community Support

Hi @Anonymous ,

Do these answers make sense? If so, please mark the helpful answers as the solutions. Then we will be able to close the case. More people will benefit from here. Thanks in advance.

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-xuding-msft
Community Support
Community Support

Hi @Anonymous ,

I add a few blogs and videos that you could reference to learn more about the function of DATEADD.

Using DATEADD() and other Date Tips for Filtering Data in Power BI 

The DATEADD Function: The Best And Most Versatile Time Intelligence Function in Power BI 

DATEADD function (DAX) - DAX DATEADD function In Power BI Desktop 

DAX Fridays #16: DATEADD 

 

Best Regards,

Xue Ding

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

@Anonymous , as explained by @az38 you can not use dateadd. He also suggested solution. You can also create a date add like this

 

New Date = date(year(table[date])+0,month(table[date])+0,day(table[date])+0)

+0 is what you have replace in year , month or date

To add 7 days

New Date = date(year(table[date]),month(table[date]),day(table[date])+7)

To add 7 Months

New Date = date(year(table[date]),month(table[date])+7,day(table[date]))

You can add more than 12 month too

 

az38
Community Champion
Community Champion

Hi @Anonymous 

dateadd() is a very tricky function

according https://docs.microsoft.com/en-us/dax/dateadd-function-dax

The result table includes only dates that exist in the dates column.

If the dates in the current context do not form a contiguous interval, the function returns an error.

so, if your data model doesnt ensure continious of dates it's better to use statements like 

Table[Date] + 90

or to create a Calendar Table for more complicated calculations

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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