Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredJoin us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.
Hi all,
I am trying to retrieve a value from a table that has certain conditions (between two dates), but I got lost on my DAX. It would be great if one of you was able to help.
My Employee Table looks something like this:
EMPLOYEE_ID | CONTRACT_STARTDATE | CONTRACT_ENDDATE |
12545 | 1-1-2022 | 12-31-2022 |
12545 | 1-1-2023 | 12-31-2023 |
54654 | 5-1-2021 | 9-30-2021 |
54654 | 10-1-2021 | 12-31-2021 |
54654 | 1-1-2022 | 12-31-2022 |
54654 | 1-1-2023 | 1-1-2024 |
84562 | 6-1-2022 | 6-1-2026 |
21536 | 1-1-2022 | 12-31-2022 |
21536 | 1-1-2023 | 1-1-2027 |
I want to create a measure that counts the number of employees in a certain date range that is filtered with date slicers (based on my date table) in my report. The Employee table can have an inactive many to one relationship with the date table (not an active one, because it's a dim table).
I made a measure that works that calculates the number of employees that started in the period that is selected with the inactive relationship, but that's not the calculation I want. I want the number of employees within the range of Contract start and Contract end.
Number of employees = CALCULATE(DISTINCTCOUNT('Dim Employees'[EMPLOYEE_ID]), USERELATIONSHIP('Dim Calender'[DATE], 'Dim Employees'[CONTRACT_STARTDATE]))
Is there a way to solve this? Preferably within the dax measure itself.
Thanks!
Solved! Go to Solution.
Hi @frankyjones
please try
Number of employees =
VAR MaxDate =
MAX ( 'Calender'[DATE] )
VAR MinDate =
MIN ( 'Calender'[DATE] )
RETURN
COUNTROWS (
FILTER (
VALUES ( 'Dim Employees'[EMPLOYEE_ID] ),
NOT ISEMPTY (
FILTER (
CALCULATETABLE ( 'Dim Employees' ),
'Dim Employees'[CONTRACT_STARTDATE] <= MaxDate
&& 'Dim Employees'[CONTRACT_ENDDATE] >= MinDate
)
)
)
)
Awesome, worked like charm 👍
Hi @frankyjones
please try
Number of employees =
VAR MaxDate =
MAX ( 'Calender'[DATE] )
VAR MinDate =
MIN ( 'Calender'[DATE] )
RETURN
COUNTROWS (
FILTER (
VALUES ( 'Dim Employees'[EMPLOYEE_ID] ),
NOT ISEMPTY (
FILTER (
CALCULATETABLE ( 'Dim Employees' ),
'Dim Employees'[CONTRACT_STARTDATE] <= MaxDate
&& 'Dim Employees'[CONTRACT_ENDDATE] >= MinDate
)
)
)
)
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
6 | |
4 | |
3 | |
3 |
User | Count |
---|---|
11 | |
11 | |
8 | |
8 | |
8 |