Forum Discussion
Need Help! Calculations based on Date Filters
- 6 years ago
Hi, Anonymous
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
Calendar(a calculated table):
Calendar = CALENDARAUTO()There is no relationship between two tables. You may create a measure as below.
Result = var _minslicerdate = CALCULATE(MIN('Calendar'[Date]),ALLSELECTED('Calendar')) var _maxslicerdate = CALCULATE(MAX('Calendar'[Date]),ALLSELECTED('Calendar')) var tab = ADDCOLUMNS( 'Table', "Result", var _startdate = [Start Date] var _finishdate = [Finish Date] return SWITCH( TRUE(), _startdate>=_minslicerdate&&_finishdate<=_maxslicerdate, DATEDIFF(_startdate,_finishdate,DAY), _startdate<_minslicerdate&&_finishdate>=_minslicerdate&&_finishdate<=_maxslicerdate, DATEDIFF(_minslicerdate,_finishdate,DAY), _startdate<_minslicerdate&&_finishdate>_maxslicerdate, DATEDIFF(_minslicerdate,_maxslicerdate,DAY), _startdate>=_minslicerdate&&_startdate<=_finishdate&&_finishdate>_maxslicerdate, DATEDIFF(_startdate,_maxslicerdate,DAY) ) ) return SUMX( tab, [Result] )Then you need to use the date column from 'Calendar' table to filter the result.
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, Anonymous
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
Calendar(a calculated table):
Calendar = CALENDARAUTO()
There is no relationship between two tables. You may create a measure as below.
Result =
var _minslicerdate = CALCULATE(MIN('Calendar'[Date]),ALLSELECTED('Calendar'))
var _maxslicerdate = CALCULATE(MAX('Calendar'[Date]),ALLSELECTED('Calendar'))
var tab =
ADDCOLUMNS(
'Table',
"Result",
var _startdate = [Start Date]
var _finishdate = [Finish Date]
return
SWITCH(
TRUE(),
_startdate>=_minslicerdate&&_finishdate<=_maxslicerdate,
DATEDIFF(_startdate,_finishdate,DAY),
_startdate<_minslicerdate&&_finishdate>=_minslicerdate&&_finishdate<=_maxslicerdate,
DATEDIFF(_minslicerdate,_finishdate,DAY),
_startdate<_minslicerdate&&_finishdate>_maxslicerdate,
DATEDIFF(_minslicerdate,_maxslicerdate,DAY),
_startdate>=_minslicerdate&&_startdate<=_finishdate&&_finishdate>_maxslicerdate,
DATEDIFF(_startdate,_maxslicerdate,DAY)
)
)
return
SUMX(
tab,
[Result]
)
Then you need to use the date column from 'Calendar' table to filter the result.
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous6 years agoNot applicable
Thank you v-alq-msft , this helps!