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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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]
)

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.