Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

Power BI Slicer 12 months automatic selection

Hi,

I have a slicer with YYYYMM values and it contains data for multiple years and new data is loaded each month. Currently as per requirement I have manually selected latest 12 months( From 202109 to 202208) and published the report. I need to automate this, in this case once 202209 data is loaded in report slicer automatically picks new recent 12 months i.e., from 202110 to 202209. Please help me on this or any work around.

 

depp_1-1666245711206.png

 

Tagging some of the known experts : @amitchandak  @Greg_Deckler  @parry2k 

1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please try this custom visual:

Preselected Slicer

 

And use measure like this as the Pre selection:

 

_Month = 
VAR __Month_1 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-1,1), "YYYYMM")
VAR __Month_2 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-2,1), "YYYYMM")
VAR __Month_3 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-3,1), "YYYYMM")
VAR __Month_4 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-4,1), "YYYYMM")
VAR __Month_5 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-5,1), "YYYYMM")
VAR __Month_6 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-6,1), "YYYYMM")
VAR __Month_7 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-7,1), "YYYYMM")
VAR __Month_8 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-8,1), "YYYYMM")
VAR __Month_9 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-9,1), "YYYYMM")
VAR __Month_10 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-10,1), "YYYYMM")
VAR __Month_11 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-11,1), "YYYYMM")
VAR __Month_12 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-12,1), "YYYYMM")
VAR __SelectedMonth = SELECTEDVALUE('Date'[Year Month])
RETURN 
    __SelectedMonth IN {__Month_1,__Month_2,__Month_3,__Month_4,__Month_5,__Month_6,__Month_7,__Month_8,__Month_9,__Month_10,__Month_11,__Month_12}

 

result:

vcgaomsft_0-1666340974254.png

vcgaomsft_0-1666341080228.png

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

2 REPLIES 2
v-cgao-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please try this custom visual:

Preselected Slicer

 

And use measure like this as the Pre selection:

 

_Month = 
VAR __Month_1 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-1,1), "YYYYMM")
VAR __Month_2 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-2,1), "YYYYMM")
VAR __Month_3 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-3,1), "YYYYMM")
VAR __Month_4 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-4,1), "YYYYMM")
VAR __Month_5 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-5,1), "YYYYMM")
VAR __Month_6 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-6,1), "YYYYMM")
VAR __Month_7 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-7,1), "YYYYMM")
VAR __Month_8 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-8,1), "YYYYMM")
VAR __Month_9 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-9,1), "YYYYMM")
VAR __Month_10 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-10,1), "YYYYMM")
VAR __Month_11 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-11,1), "YYYYMM")
VAR __Month_12 = FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-12,1), "YYYYMM")
VAR __SelectedMonth = SELECTEDVALUE('Date'[Year Month])
RETURN 
    __SelectedMonth IN {__Month_1,__Month_2,__Month_3,__Month_4,__Month_5,__Month_6,__Month_7,__Month_8,__Month_9,__Month_10,__Month_11,__Month_12}

 

result:

vcgaomsft_0-1666340974254.png

vcgaomsft_0-1666341080228.png

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

amitchandak
Super User
Super User

@Anonymous , No(we need work around), we have to create a text like the last 12 months and use that in the selection and that will change automatically

 

a new column in table

 

lasr 12 Months Type = Switch( True(),
([Date]) >= eomonth(Today(),-11) && Date([Date])<= eomonth(Today(),0) ,"Last 12 Months" , //Last Month // or use -12
([Date])= eomonth(Today(),0),"Other Months" , //This Month
[Month Year]
)

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.