Forum Discussion

Sachintha's avatar
Sachintha
Icon for Helper III rankHelper III
1 year ago
Solved

Filtering slicer based on values in a related table

I have a dataset of employee work hours logged. The employees will log their work hours each day - key point being that not every employee will log hours for every day. These employees are shift work...
  • Sachintha's avatar
    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.

     

    1. 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.