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
PbiCeo
Helper II
Helper II

How to resolve the error A function 'DATEADD' has been used in a True/False expression that is used

Hello everyone,

I want to sum Amount with some conditions like below:
If a year month value is 2019 or 2020, it sums Amount of 1 year ago with 2 days plus.
(for example, 2020/1/1 -> value of 2019/1/3)
If a year month value is not 2019 or 2020, it sums Amount of of 1 year ago with 1 day minus.
However, got the error with the below measure.


measure :=
CALCULATE (
SUM ( 'Table'[Amount] ),
'Table'[Status] IN { "A" },
IF (
LEFT ( 'CALENDAR'[YEARMONTH], 4 ) IN { "2019", "2020" },
DATEADD ( DATEADD ( 'CALENDAR'[Date], -1, YEAR ), 2, DAY ),
DATEADD ( DATEADD ( 'CALENDAR'[Date], -1, YEAR ), 1, DAY )
)
)

Error:
A function 'DATEADD' has been used in a True/False expression that is used as a table filter expression.
This is not allowed.

How can I resolve that?

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Encapsulate it in a FILTER() .

 

measure :=
CALCULATE (
SUM ( 'Table'[Amount] ),
'Table'[Status] IN { "A" },
FILTER(CALENDER,IF (
LEFT ( 'CALENDER'[YEARMONTH], 4 ) IN { "2019", "2020" },
DATEADD ( DATEADD ( 'CALENDER'[Date], -1, YEAR ), 2, DAY ),
DATEADD ( DATEADD ( 'CALENDER'[Date], -1, YEAR ), 1, DAY )
))
)

 

Btw, it's Calendar, not Calender. 🙂

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

Encapsulate it in a FILTER() .

 

measure :=
CALCULATE (
SUM ( 'Table'[Amount] ),
'Table'[Status] IN { "A" },
FILTER(CALENDER,IF (
LEFT ( 'CALENDER'[YEARMONTH], 4 ) IN { "2019", "2020" },
DATEADD ( DATEADD ( 'CALENDER'[Date], -1, YEAR ), 2, DAY ),
DATEADD ( DATEADD ( 'CALENDER'[Date], -1, YEAR ), 1, DAY )
))
)

 

Btw, it's Calendar, not Calender. 🙂

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