Forum Discussion
Latest Week Slicer update
- 1 year ago
Hi Sravanthi_B
Your week range column seems to be sorted correctly so I would use the custom column sort to filter the slicer.
Below is a sample calculated column to determine whether a week ending date is in the last 8 weeks ending dates
Last 8 Weeks = Dates[Week Ending Sunday] IN TOPN ( 8, VALUES ( Dates[Week Ending Sunday] ), Dates[Week Ending Sunday], DESC )Use the calculated column as a visual filter
As to the selection to default to the last week, you can leverage the Group by Columns property to "store a filter by using an alternate value, which represents the key of the entity." Power BI uses this key to store the filter, allowing the corresponding filter value in the visual to change dynamically. For instance, if May-24 is selected in the visual and currently has a key of 0, when June arrives, May will shift to a key of 1, and June will take the key of 0. Consequently, the slicer selection will automatically change to June. This property can be accessed using an external tool called Tabular Editor. Demo and further reference can be found here - https://youtu.be/MrEAZREQuXM
In my example, I used RANKX to create an offset column.
Please refer to the attached pbix
- 1 year ago
Hi Sravanthi_B ,
Thank you for reaching out to Microsoft Fabric Community.
Thank you burakkaragoz danextian for the prompt response.
You can show only the latest 8 weeks in your slicer by ranking weeks using their end date. To make sure it updates as new data comes in, use a dynamic filter based on that ranking. Power BI doesn’t let slicers auto-select a value by default, but with a tool like Tabular Editor, you can mark the latest week to be pre-selected. This way, the slicer stays current and highlights the latest week without manual updates.
Thank you.
Hi burakkaragoz ,
Thanks for the help. However, the issue is that the DAX provided displays only the latest week.
What we need is to display the last 8 weeks, including the latest week, in the week slicer and the default selection should be the latest week.
Thanks in advance.
- burakkaragoz1 year agoSuper User
Ah got it, I misunderstood your requirement! You want the slicer to show the last 8 weeks but have the latest week selected by default.
Here's what you need to do:
Step 1: Filter your Week table to show last 8 weeks Create a calculated column or use a filter:
Show in Slicer = VAR LatestWeekEnd = MAXX( 'Week', DATEVALUE(RIGHT(SUBSTITUTE('Week'[Week Range], " - ", REPT(" ", 50)), 11)) ) VAR CurrentWeekEnd = DATEVALUE(RIGHT(SUBSTITUTE([Week Range], " - ", REPT(" ", 50)), 11)) VAR WeeksDiff = (LatestWeekEnd - CurrentWeekEnd) / 7 RETURN IF(WeeksDiff <= 7, 1, 0)Step 2: Filter your slicer Add this column to your slicer's filter and show only where "Show in Slicer" = 1.
Step 3: Set default selection Unfortunately, Power BI doesn't have built-in "default selection" for slicers. You have a few options:
- Use bookmarks to save the latest week selection
- Create the report with the latest week pre-selected and save it that way
- Use Power BI Service's "persistent filters" feature
The slicer will now show 8 weeks, and you can set up bookmarks to automatically select the latest one when the report loads.