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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.