Forum Discussion
coast2coast
2 years agoNew Member
DAX Measure Function DATESINPERIOD - sum while excluding current week
Trying to use these measures to sum values 3 weeks before and after current week, while excluding current week values. These measures work to get the correct values for the current week and ID, how...
- Anonymous2 years ago
HI coast2coast,
Perhaps you can try to use date function to manually calculate the date range for the calculated conditions:
3weekPrev = VAR currDate = MAX ( Query1[WEEK_START_DATE] ) VAR eDate = currDate - WEEKDAY ( currDate, 1 ) RETURN CALCULATE ( SUM ( Query1[DAYS] ), FILTER ( ALLSELECTED ( Query1 ), Query1[WEEK_START_DATE] >= DATE ( YEAR ( eDate ), MONTH ( eDate ), DAY ( eDate ) - 20 ) && Query1[WEEK_START_DATE] <= eDate ) ) 3weekForward = VAR currDate = MAX ( Query1[WEEK_START_DATE] ) VAR sDate = currDate - WEEKDAY ( currDate, 1 ) + 7 RETURN CALCULATE ( SUM ( Query1[DAYS] ), FILTER ( ALLSELECTED ( Query1 ), Query1[WEEK_START_DATE] > sDate && Query1[WEEK_START_DATE] <= DATE ( YEAR ( sDate ), MONTH ( sDate ), DAY ( sDate ) + 21 ) ) )Regards,
Xiaoxin Sheng
Anonymous
2 years agoNot applicable
HI coast2coast,
Perhaps you can try to use date function to manually calculate the date range for the calculated conditions:
3weekPrev =
VAR currDate =
MAX ( Query1[WEEK_START_DATE] )
VAR eDate =
currDate - WEEKDAY ( currDate, 1 )
RETURN
CALCULATE (
SUM ( Query1[DAYS] ),
FILTER (
ALLSELECTED ( Query1 ),
Query1[WEEK_START_DATE]
>= DATE ( YEAR ( eDate ), MONTH ( eDate ), DAY ( eDate ) - 20 )
&& Query1[WEEK_START_DATE] <= eDate
)
)
3weekForward =
VAR currDate =
MAX ( Query1[WEEK_START_DATE] )
VAR sDate =
currDate - WEEKDAY ( currDate, 1 ) + 7
RETURN
CALCULATE (
SUM ( Query1[DAYS] ),
FILTER (
ALLSELECTED ( Query1 ),
Query1[WEEK_START_DATE] > sDate
&& Query1[WEEK_START_DATE]
<= DATE ( YEAR ( sDate ), MONTH ( sDate ), DAY ( sDate ) + 21 )
)
)
Regards,
Xiaoxin Sheng