Forum Discussion
Read slicer values, retrieve corresponding table column values and use them to check existence
- 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,
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,
- kevinfernandez1 year agoFrequent Visitor
Thanks DataNinja777
This is what exactly I was looking for. The VALUES dax along with CALCULATETABLE helps in bringing the exact dates while using the slicer and use those dates to see the matches in my calculation. The IN keyword is another catch that helped in my calculation too.