Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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?
Solved! Go to Solution.
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. 🙂
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. 🙂
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
11 | |
11 | |
10 | |
10 |
User | Count |
---|---|
19 | |
14 | |
13 | |
11 | |
8 |