Join 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!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hi I am trying to count active employers aggregated per month, I have a start date and a end date and a date 9999-12-31 if its still active or without end date. The start date can be greater than the actul day.
My code count employers that have a start date after this day
Solved! Go to Solution.
If you're trying to ignore people with a start date in the future you could add another clause to the FILTER
Aktiva personer =
CALCULATE (
DISTINCTCOUNT ( 'analytics employment_periods'[sk_employment] ),
FILTER (
'analytics employment_periods',
'analytics employment_periods'[Period_start_datum] >= MIN ( 'Kalender'[Date] )
&& 'analytics employment_periods'[Period_start_datum] <= TODAY ()
&& (
'analytics employment_periods'[Period_slut_datum] <= MAX ( 'Kalender'[Date] )
|| 'analytics employment_periods'[Period_slut_datum] = DATE ( 9999, 12, 31 )
)
)
)
If you're trying to ignore people with a start date in the future you could add another clause to the FILTER
Aktiva personer =
CALCULATE (
DISTINCTCOUNT ( 'analytics employment_periods'[sk_employment] ),
FILTER (
'analytics employment_periods',
'analytics employment_periods'[Period_start_datum] >= MIN ( 'Kalender'[Date] )
&& 'analytics employment_periods'[Period_start_datum] <= TODAY ()
&& (
'analytics employment_periods'[Period_slut_datum] <= MAX ( 'Kalender'[Date] )
|| 'analytics employment_periods'[Period_slut_datum] = DATE ( 9999, 12, 31 )
)
)
)
Tnx for a really good solution
Thanx but it stil the same problem here is a example of people that conut that shouldn't
They have a start date for example 2026-01 and so on
Hi @ElinG,
I reproduced the issue using the sample data and obtained the following output. I have attached the PBIX file for your reference.
Aktiva personer =
CALCULATE(
DISTINCTCOUNT('employment_periods'[sk_employment]),
FILTER(
'employment_periods',
'employment_periods'[Period_start_datum] <= MAX('Kalender'[Date])
&& (
'employment_periods'[Period_slut_datum] >= MIN('Kalender'[Date])
|| 'employment_periods'[Period_slut_datum] = DATE(9999,12,31)
)
)
)
Hope this helps
Thank you.
Hi, your logic is employees are active if their start date is before or equal to the end of the period you’re looking at,
and their end date is either missing / 9999-12-31, or after the start of the period. so try this instead,
I just suggest an optmization of @MasonMA great code
If the table you have is huge, the below can improve performance
If this helped, please consider giving kudos and mark as a solution
@me in replies or I'll lose your threadWant to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI