Forum Discussion
Filtering slicer based on values in a related table
- 1 year ago
Unfortunately none of the replies seem to address the core issue, so I dived into this a bit and came up with a solution.
- Create a separate WorkWeek table in PowerQuery.
I created a separate table called WWs by referncing the WorkHours table, added the WW column, and removed duplicates based on WW. Notice the Table.Buffer() encompassing the Table.Sort(), which is necessary when removing duplicates and wanting to adhere to the sort order. Finally, I filtered to keep only the WWs where PayPeriod = Current.
let Source = WorkHours, #"Added Custom" = Table.AddColumn(Source, "WW", each "WW-" & Text.From(Date.WeekOfYear([Date]))), #"Sorted Rows" = Table.Buffer(Table.Sort(#"Added Custom",{{"Date", Order.Descending}})), #"Removed Duplicates" = Table.Distinct(#"Sorted Rows", {"WW"}), #"Removed Other Columns" = Table.SelectColumns(#"Removed Duplicates",{"WW", "PayPeriod"}), #"Filtered Rows" = Table.SelectRows(#"Removed Other Columns", each ([PayPeriod] = "Current")) in #"Filtered Rows"The resulting table looks like this:
I did NOT set a relationship between this and the other tables.
Also, note that I no longer need the WW column in the WorkHours table.- Add a CurrentWWs column to the DateTable
I created the DateTable same as before, and linked with the WorkHours table by Date.
DateTable = ADDCOLUMNS( CALENDAR(DATE(2024, 1, 1), DATE(2024, 11, 30)), "WW", "WW-" & FORMAT(WEEKNUM([Date]), "00") )Then I added a CurrentWWs column by LOOKUPVALUE() on WWs table.
CurrentWWs = LOOKUPVALUE(WWs[WW], WWs[WW], DateTable[WW])The resulting DateTable looks like below. Essentially, the CurrentWWs column has the WW if it falls within a WW where the PayPeriod is Current in the WorkHours table. Otherwise, empty.
- Add 'Filters on this page'
Add a 'Filters on this page' using the CurrentWWs column, set it to display the CurrentWWs that are not blank. - Set the Matrix and Slicers as below
WW Slicer using WW column in DateTable.Matrix as below. Note the WW and Date is from the DateTable.
This will yield the expected result, while the WW filter only showing the WWs for which PayPeriod = Current.
- Create a separate WorkWeek table in PowerQuery.
Ashish_Mathur this is not doing what I need.
1. I want to filter by WW and Employee, and when I do so, it should show each day of the week even if they have not entered a value for that day. But it should NOT show any days that's outside the PayPeriod = Current window.
2. I need the WW slicer to also show only the WW's that are in the PayPeriod = Current window.
Hi,
Drag this measure
- Sachintha1 year ago
Helper III
This still does not address the main issue. As mentioned in my original post, in my own PIBX file I can already get the matrix to display dates without any data entered and have background formatted. This part works fine.
My question is how do I get the WW dropdown to show only the WWs for which entries are marked as PayPeriod = Current. In other words, based on data, only the WWs 45 and 46 are 'current' WWs. As such, I want the dropdown to show only those two WWs as options that the user can select.