Forum Discussion
Syndicate_Admin
Administrator
5 years agoSlicer initializer
Good morning I have the following question How to initialize a slicer so that it always starts at the same value when a report is opened. For example, that whenever we open the CUSTOMERS report...
- 5 years ago
Here's a more performant solution. Create a calculated table as follows (you could also do this in Power Query):
FactTableMaxYear = { YEAR ( MAX ( FactTable[Date] ) ) }The result is a one-row, one-column table. Then, refer to this table in the calculated column:
Slicer Year = VAR vMaxYear = MAX ( FactTableMaxYear[Value] ) VAR vResult = SWITCH ( TRUE (), 'Calendar'[Year] = vMaxYear, "Current Year", 'Calendar'[Year] < vMaxYear, 'Calendar'[Year] & "" ) RETURN vResult
DataInsights
Super User
5 years ago
Try this solution.
1. In the Calendar table, add this calculated column. The table FactTable is your data table.
Slicer Year =
VAR vMaxYear =
YEAR ( MAX ( FactTable[Date] ) )
VAR vResult =
SWITCH (
TRUE (),
'Calendar'[Year] = vMaxYear, "Current Year",
'Calendar'[Year] < vMaxYear, 'Calendar'[Year] & ""
)
RETURN
vResult
2. Create a slicer based on this calculated column. Set the visual filter to "is not blank". Sort descending.
- DataInsights5 years ago
Super User
Here's a more performant solution. Create a calculated table as follows (you could also do this in Power Query):
FactTableMaxYear = { YEAR ( MAX ( FactTable[Date] ) ) }The result is a one-row, one-column table. Then, refer to this table in the calculated column:
Slicer Year = VAR vMaxYear = MAX ( FactTableMaxYear[Value] ) VAR vResult = SWITCH ( TRUE (), 'Calendar'[Year] = vMaxYear, "Current Year", 'Calendar'[Year] < vMaxYear, 'Calendar'[Year] & "" ) RETURN vResult