Forum Discussion
Error using slicer to filter between start and end dates
- 6 years ago
Hi, trt18-sistemas
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()You may create calculated columns and a measure as below.
Calculated column:
Calendar Year Month = YEAR('Calendar'[Date])*100+MONTH('Calendar'[Date]) Start Year Month = YEAR('Table'[Start Date])*100+MONTH('Table'[Start Date]) End Year Month = YEAR('Table'[End Date])*100+MONTH('Table'[End Date])Measure:
Visual Control = var _yearmonth = SELECTEDVALUE('Calendar'[Calendar Year Month]) var tab = ADDCOLUMNS( 'Table', "flag", IF( ISBLANK([End Year Month]), IF( [Start Year Month]<=_yearmonth, 1,0 ), IF( [Start Year Month]<=_yearmonth&& [End Year Month]>=_yearmonth, 1,0 ) ) ) return SUMX( tab, [flag] )Finally you may put the measure in the visual level filter and use the year-month 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, trt18-sistemas
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()
You may create calculated columns and a measure as below.
Calculated column:
Calendar Year Month = YEAR('Calendar'[Date])*100+MONTH('Calendar'[Date])
Start Year Month = YEAR('Table'[Start Date])*100+MONTH('Table'[Start Date])
End Year Month = YEAR('Table'[End Date])*100+MONTH('Table'[End Date])
Measure:
Visual Control =
var _yearmonth = SELECTEDVALUE('Calendar'[Calendar Year Month])
var tab =
ADDCOLUMNS(
'Table',
"flag",
IF(
ISBLANK([End Year Month]),
IF(
[Start Year Month]<=_yearmonth,
1,0
),
IF(
[Start Year Month]<=_yearmonth&&
[End Year Month]>=_yearmonth,
1,0
)
)
)
return
SUMX(
tab,
[flag]
)
Finally you may put the measure in the visual level filter and use the year-month 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.