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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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