How to Set Default Slicer selection to Current Year / Month in Power BI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys and welcome to power bison so today we are going to see how you can default your slicer to the current year so I'm recording this video as of 22nd of September 2023 so since it's 2023 the ask will be the uh you know the year slicer so by default have 2023 selected so when we go to the next year which is 2024 it should automatically change to 2024. so uh to achieve this you can achieve this in two ways so I'll be making a separate video on the second method this we are going to try to do it very easily uh using a custom Visual and a very simple tax so let's get started okay so what you need to do is you need to first of all have obviously a date table in your model so this is my main table which is the who data and this is my date Dimension my date Dimension will be linked to my who data using one to many relationship right because in the date Dimension a date will occur only once and you have to use this date dimension in your slicer right in your slicer that you will create so I hope the basics are absolutely clear so let's get started now as per the requirement we are not going to use much of Dax over here and we will try to do this very simply you have to right click go to get more visuals there will be just slide search with slicer okay so this is the one that we are talking about pre-selected slicer right it has the Blue Tick so you can go ahead and import this add this to your canvas okay now the date table you so right now I am showing it for the year so for the year I'll be using this particular column which is in my table let me show that to you so that things will be dead clear let's see the data okay this is going to be the data for the year right so this is my year which contains let's say 2020 2021 22 and 23 right so I'll be using this particular column as my slicer obviously from the date Dimension so let me go ahead and add this under fields now there are two things pre-selection and dirty status so for the dirty status you have to give a binary uh column right so for that we need to go to enter data and create two Terminator of just true and false name the table as status flag and the column and Status which just has two values which is true and false section so let me go ahead and add the status and it will show this particular error message but do not worry we also have to create a measure which will be very simple measure so I'll go to new measure okay I hope you're able to see this now let me go ahead and do a control enter to come into the next line so pre-selection condition I'll write as Max of you know the date that I want to give or rather the year column from date Dimension right and I'll say Max of the year is equal to so I will try to extract the year from today so there is a function called today which will give me obviously today is date and from there I need to extract the year okay so now we simply drag and drop this now guys the beauty of this particular simple uh you know Dax is if you want you know default selection for the past two years you you know you all you have to do is write like this particular year is greater than equal to here minus 1. right so it is going to be 2022 and 23 both of them will be selected now let us quickly see how you can go ahead and sort it for a month year combination right so for that I have taken the same visual over here which is again uh pre-selected slicer and why I wanted to use the date table now you will find a lot of advantages over here so month year is already pre-calculated in my date table so if I go to my date table select the date dimension and scroll towards the last the these These are the this is the column that I'm talking about year month right so which you can go ahead and use easily uh and in the back end remember you have to use year month code as well which is of type number right so uh this year month is of type text but year month code is of type number right so you can go ahead and use that as well how very interestingly what we have done over here is we have written one more measure right over here I am taking Max of year month code as I told you that I need to do a Max of a number type of column right I cannot do a Max of text so that's why I've taken year month code and equals I have taken year of today so from today I'm extracting the year and multiplying this with 100 okay and then I will extract month from today so it will be again a combination of the year which is 2023 multiply it with 100 so it will be 2 0 2 3 0 0 plus the month so month will always give you a number so what is the month going on it is 0 9 which is September right so my year code will match with this year code and this will be true this particular measure and you have to pull that measure in the pre-selection right so why it is not showing that's because I was trying to play around with this all you have to do is reset this right as soon as you click on reset and scroll down you will be able to see the present month which is September 2023 selected now this might look a bit odd the the year selection with a lot of value so what I'll do is I'll try to do this neatly so let me go ahead and go to the visual and from visual instead of list I also this as a drop down so I hope you're liking my video guys and if you are liking my videos please do not forget to subscribe bye
Info
Channel: PowerBI Zone
Views: 19,388
Rating: undefined out of 5
Keywords: Default Year or Month Power BI, Default slicer value power bi, slicer current period power bi, Slicer current month, slicer default current year, power bi set slicer to current month, slicer dynamic default value, slicer dynamic slicer filter, set default slicer value, power bi desktop, power bi, power bi interview questions, power bi project, power bi tutorial
Id: o-gr3XgU1mg
Channel Id: undefined
Length: 6min 51sec (411 seconds)
Published: Sat Sep 23 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.