Forum Discussion
Customize Date Slicer
For the below two slicers, the "Select date" filter should operate the second slicer and the selected date should be the end date in below slicer.
e.g As shown I have 30/12/23 as select date, that should be the end date in below table, and start date is 7 days before that is 23/12/23, but by default it's taking todays date as default date, which should not be the case.
How can I achive this?
1 Reply
- amitchandakSuper User
Anonymous , You have to follow the approach given in the solution. You might have to use 3 slicers (one of them can be a numeric parameter and modify measure
example code
Disconnected Tables
PeriodType = DATATABLE("Period", STRING, {
{"Day"},
{"Month"},
{"Qtr"},
{"Year"}
})Calendar =
CALENDAR(
DATE(2020, 1, 1), // Start date
DATE(2023, 12, 31) // End date
)Create numeric parameter from Modelling Tab
Parameter/What if Parameter: https://youtu.be/OB2ta2zEhl8Measure
DynamicTimePeriod =
VAR _SelectedPeriodType = SELECTEDVALUE(PeriodType[Period])
VAR _NumPeriods = [NumericParameter] // This would be your numeric parameter
VAR _LastDate = MAX('Date'[Date]) // Adjust this if you need a different reference date
VAR _StartDate =
SWITCH(
_SelectedPeriodType,
"Day", DATEADD(_LastDate, -_NumPeriods, DAY),
"Month", DATEADD(_LastDate, -_NumPeriods, MONTH),
"Qtr", DATEADD(_LastDate, -_NumPeriods*3, MONTH),
"Year", DATEADD(_LastDate, -_NumPeriods, YEAR),
_LastDate // Default case to avoid errors
)
VAR Result =
CALCULATE(
SUM('Table'[Values]),
FILTER(
'Table',
'Table'[LastUpdatedDate] <= _LastDate && 'Table'[LastUpdatedDate] >= _StartDate
)
)
RETURN
Result