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
Anonymous
Not applicable

DATEADD in calculated table cannot use column

Hello,

 

I have following code that creates calculated table with dates for 12 months rolling period.

For some reason I cannot use DATEADD function using column (it gets underlined as error and table does not materialize). I have this stupid workaround to use just [YearMonthTrunc_B]>([YearMonthTrunc_A]-365) but this is causing some issues for leap-years.

 

Is there something better to use than DATEADD?

 

Thanks for any response,

Zuzana

 

Table = 
var monthrange = SELECTCOLUMNS( ADDCOLUMNS(SUMMARIZECOLUMNS('_Date - renewal'[YearMonthTrunc])
                                ,"YearMonth",FORMAT('_Date - renewal'[YearMonthTrunc],"YYYY/MM"))
                 ,"YearMonth_A",[YearMonth]
                 ,"YearMonthTrunc_A",[YearMonthTrunc])
var rollingperiod = SELECTCOLUMNS( ADDCOLUMNS(SUMMARIZECOLUMNS('_Date - renewal'[YearMonthTrunc])
                                   ,"YearMonth",FORMAT('_Date - renewal'[YearMonthTrunc],"YYYY/MM"))
                 ,"YearMonth_B",[YearMonth]
                 ,"YearMonthTrunc_B",[YearMonthTrunc])
                                  
return
FILTER(CALCULATETABLE(CROSSJOIN(monthrange,rollingperiod))
       ,AND([YearMonthTrunc_B]<=[YearMonthTrunc_A]
       ,[YearMonthTrunc_B]>DATEADD([YearMonthTrunc_A],-12,MONTH))
       )
            

Table '_Date - renewal' is also calculated:

_Date - renewal = 
ADDCOLUMNS (
CALENDAR (min(data[start_date]),TODAY()),
"YearMonthTrunc", date(year([date]),month([date]),1),
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Functions that work with dates need input that is a DATE (and even though sometimes type coercion kicks in, you should NEVER rely on that), so please make sure you have the right input into your functions. What's more, some of them need input in the form of a column with specific data types, some work on pure dates (disconnected from any tables). For the correct syntax and data types, please refer to DAX Guide. You'll find everything you need in there.

 

By the way...

 

var __today = TODAY()
var __todayBackInTime = EDATE( __today, -12 ) 
return
	{ __todayBackInTime }

 

Best

Darek

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Functions that work with dates need input that is a DATE (and even though sometimes type coercion kicks in, you should NEVER rely on that), so please make sure you have the right input into your functions. What's more, some of them need input in the form of a column with specific data types, some work on pure dates (disconnected from any tables). For the correct syntax and data types, please refer to DAX Guide. You'll find everything you need in there.

 

By the way...

 

var __today = TODAY()
var __todayBackInTime = EDATE( __today, -12 ) 
return
	{ __todayBackInTime }

 

Best

Darek

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.