Default Your Slicer to the Current Month in Power BI
Wyn Hopkins
Solving data challenges for companies and people. Power BI | Excel | Fabric | Solver Budgeting & Consolidation. Part of the Amazing team at Access Analytic Microsoft MVP ??6 Million+ YouTube views
First Published November 2022 on our YouTube Channel
Join 65,000+ subscribers to stay up to date with new videos release every week.
Is it possible to default your slicer to the current month? No.
But wait..you can..and here's a breakdown on how to do just that.
Watch the video or read on below:
The End Result
Let's start by looking at the end result. We have a month slicer that displays an option for the current month. This feature can be especially handy when you want to keep your data up to date, whether you're manually refreshing it or have it set to auto-refresh.?
Once the data is refreshed, the slicer will automatically update to show the new current month, ensuring that you're always viewing the most recent data.
Adjusting Your Power Query Calendar
The magic behind this is a special calendar table built in Power Query, equipped with handy columns such as 'Months since today', 'Weeks since current month', and a few others.
You can set up this calendar so that whenever the 'Months since today' column hits zero (which signifies the current month), it outputs the word 'Current'. This is done using a simple conditional formula.?
You can download the file and take a look at the code here
The table also has a 'Sort by' column, which helps to ensure that 'Current' is always the first option in your slicer.
领英推荐
Understanding "Current"
Before you proceed, it's important to clarify what you mean by 'current month'.?
Are you referring to 'today' as the current date every time you refresh your data, or do you mean the latest transaction date as 'current'? Depending on your definition, you might need to adjust your calendar table slightly.
For instance, if you're going by the actual current date, you can set up your calendar table to reflect this using Date.From(DateTime.LocalNow() ).
Alternatively, if you're referring to the latest transaction date, you can use the 'List.Max' function to retrieve the maximum date from your Fact table.
Sort by Column
Remember that for this slicer to work as intended, you need to make sure the 'Sort by' column is properly set up in your slicer. This is the column that determines the order of the options in your slicer and makes sure 'Current' shows up first.
Things to Keep in Mind
While this is a handy feature, there are a couple of things to keep in mind. Firstly, the 'current' month will actually be missing from your slicer, since it's being replaced by the 'Current' option. Secondly, if you want to switch years, you'll need to click off 'Current' before you can do so.
Conclusion
This is a feature I've been experimenting with and so far, it's proving to be quite useful. Let me know what you think in the comments! See you in the next video!
You can download the file and take a look at the code here
SideNote:
The crazy thing about this article is that I didn't write it. I copied the transcript from my YouTube vidoe and pasted into ChatGPT and used a prompt to write a blog post from a YouTube transcript. It then generated the content which I modified slightly and uploaded screen shots. It's pretty amazing. For more GPT4 content I have a YouTube playlist here:
Wyn
Data Analyst at Innofactor
1 年Besides this solution and Mateusz Mossakowski, there is also a simple solution where you replace today's month, such as "Aug 2023" with value "Current month". Note: If you do the replacement in PowerQuery, then you should refresh data on morning to ensure that this works on the first day of the month. Benefits: Sorting works automatically correctly, there is only one single list of values so in this cases you just have "Current month" coming after July and before September where you would expect August.
Al-Futtaim IKEA | xNoon | xSharaf | Accounting & Finance | Reporting | Analyst | ERP | BI | SQL
1 年Thank you for sharing this. I've actually been trying to figure this out lately. Cheers ??
Husband | Dad | Business Intelligence Guy | IT Software Engineering Manager at Procter & Gamble
1 年I would allow myself to share my proposal regarding default slicer selections in PBI :) https://medium.com/@mossakowski.mateusz/dynamic-default-slicer-value-in-power-bi-f02fbec4f481