Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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
)
)
)
)
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
23 | |
9 | |
7 | |
6 | |
6 |
User | Count |
---|---|
28 | |
11 | |
11 | |
10 | |
6 |