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.
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. 🙂
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
49 | |
26 | |
21 | |
15 | |
12 |
User | Count |
---|---|
57 | |
49 | |
44 | |
19 | |
18 |