Forum Discussion
Slicer to select current month as default
- 6 years ago
Hi,
According to your description, I create a table to test:
Please take following steps:
1)create a calculated table:
Slicer =
UNION (
VAR t =
DISTINCT (
ADDCOLUMNS (
SELECTCOLUMNS ( 'Table', "Month Year", FORMAT ( 'Table'[Date], "MMMM YYYY" ) ),
"minDate", CALCULATE (
MIN ( 'Table'[Date] ),
FILTER ( 'Table', [Month Year] = FORMAT ( 'Table'[Date], "MMMM YYYY" ) )
)
)
)
RETURN
SELECTCOLUMNS (
ADDCOLUMNS ( t, "Rank", RANKX ( t, [minDate],, ASC, DENSE ) ),
"Month Year", [Month Year],
"Rank", [Rank]
),
DATATABLE ( "Month Year", STRING, "Rank", INTEGER, { { "Last Month", 0 } } )
)
And it shows:
2)create a measure:
IsFiltered =
IF (
FORMAT ( SELECTEDVALUE ( 'Table'[Date] ), "MMMM YYYY" )
IN FILTERS ( Slicer[Month Year] ),
1,
IF (
"Last Month" IN FILTERS ( Slicer[Month Year] ),
IF (
SELECTEDVALUE ( 'Table'[Date] )
>= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 )
&& SELECTEDVALUE ( 'Table'[Date] )
< DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 1 ),
1,
-1
),
-1
)
)
3)choose table visual and set measure ‘IsFiltered’ as 1:
4)choose column ‘Month Year’ of table ‘Slicer’ as a slicer:
5)choose the ‘Last Month’ and the result shows:
Here is my test pbix file:
Best Regards,
Giotto Zhi
Thanks for the suggestion, Manfred.
However, I can't insert a slicer larger than the dropdown list I have desgined.
Also, this slicer won't be relevant to my users as they only want to display our data as at a particular month rather than a range.
Tae,
Have you checked the relative date slicer option?
It will be dynamic based on the Today date. Check out here - https://docs.microsoft.com/en-us/power-bi/visuals/desktop-slicer-filter-date-range#use-the-relative-date-range-slicer
I hope It will be helpful!