Forum Discussion

kevinfernandez's avatar
kevinfernandez
Frequent Visitor
1 year ago
Solved

Read slicer values, retrieve corresponding table column values and use them to check existence

Hi all,   I am trying to retrieve a column values based on the selected single/multiple slicer values and use those data to check their existence in the other table.   Let me put this out clearly...
  • DataNinja777's avatar
    1 year ago

    Hi kevinfernandez ,

     

    You can achieve this in Power BI using a DAX measure that dynamically filters the Calendar table based on the selected fiscal period(s) in the slicer, retrieves the corresponding dates, and checks for any matches with the Joined date column in the Employee table. The idea is to create a measure that reads the selected values in the slicer, pulls the relevant dates from the calendar, and counts how many of those dates exist in the employee data.

    Here is the DAX measure that returns the count of employees who joined during the selected fiscal period(s):

    JoinedInSelectedPeriod =
    VAR SelectedDates =
        CALCULATETABLE(
            VALUES('Calendar'[Date]),
            'Calendar'
        )
    RETURN
        COUNTROWS(
            FILTER(
                'Employee',
                'Employee'[Joined date] IN SelectedDates
            )
        )
    

    This measure calculates the list of dates from the Calendar table based on the slicer selection and checks if those dates are found in the Joined date column of the Employee table. If you prefer to return a simple TRUE/FALSE flag indicating whether at least one employee joined during the selected period, you can use the following version:

    AnyJoinInSelectedPeriod =
    VAR SelectedDates =
        CALCULATETABLE(
            VALUES('Calendar'[Date]),
            'Calendar'
        )
    RETURN
        IF(
            COUNTROWS(
                FILTER(
                    'Employee',
                    'Employee'[Joined date] IN SelectedDates
                )
            ) > 0,
            TRUE,
            FALSE
        )
    

    These measures work as long as the slicer is based on 'Calendar'[Fiscal Year Period] and both date columns are of the same data type. Let me know if you'd like to display the list of employee names instead.

     

    Best regards,