Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

DAX: filter a date column based on specific dates from another Table

Hi all,

I am going nuts trying to find the solution to this problem. Hope the community might give a helping hand.

I have the following tables in my model:

(1) Table (Employees) which contains all employees with their hired dates (column name: hired_DT).

(2) Table (DateDimension) which is a DateDimension table from 01 January 2019 to 31 December 2019 (column name: date)

(3) Table (MthYrTXT) which has 2 columns, namely date and LastDayDate

MthYrTxt table looks as follows:

DateLastDayDate
2019-07-012019-07-31
2019-08-012019-08-31
2019-09-012019-09-30

 

The relationships between these 3 tables are as follows:

 

Employees[hired_DT] -------------->DateDimension[date]

MthYrTxt[date]---------------------->DateDimension[date]

 

I need  a measure that will calculate the list of active employees for July 2019, August 2019 and September 2019.

The column "Date" of MthYrTxt table will be used as Rows in my Pivot Table.

 

Active employees for a particular month = all those which have a hired_DT <= the last day of that particular month.

In other words, Active employees for July 2019 will have this logic: where hired_DT <= "2019-07-31" and so on for the remaining months.

 

How can I build this Measure?

 

1 ACCEPTED SOLUTION

@Anonymous 

 

This is in reference to the additional table you had mentioned in your orignal post:

 

(3) Table (MthYrTXT) which has 2 columns, namely date and LastDayDate

 

I have not used it in my calculation. These additional columns (Year, Month, QTR) can be used for filtering the visuals. For calculation, we just need Date column.

 

Hope this answers your query.

 

Regards,
Vivek

If it helps, please mark it as a solution

Kudos would be a cherry on the top 🙂

https://www.vivran.in/

View solution in original post

4 REPLIES 4
vivran22
Community Champion
Community Champion

Hello @Anonymous ,

 

You would need primarily two tables for this: Employee table and a calendar table with all the date related fields( Year, month, qtr, etc. You do need to create a separate table for Year)

 

I have created a sample data table for this exercise:

Capture.JPG

 

Then you need to create a calendar table using DAX:

dtCalendar =
ADDCOLUMNS (
    CALENDAR (
        MIN ( dtEmpTable[DateOfJoining] ),
        MAX ( dtEmpTable[LastDateOfWorking] )
    ),
    "Year", YEAR ( [Date] )
)

 

Establish the relationships between these two tables on Date of Joining & Last working date (if applicable)

Capture2.JPG

 

 

Then you may use following measures for the calculation

 

Joining Count =
CALCULATE (
    COUNTROWS ( dtEmpTable ),
    USERELATIONSHIP ( dtCalendar[Date], dtEmpTable[DateOfJoining] )
)


Inactive Count =
CALCULATE (
    COUNTROWS ( dtEmpTable ),
    USERELATIONSHIP ( dtCalendar[Date], dtEmpTable[LastDateOfWorking] ),
    dtEmpTable[Status] = "Inactive"
)


Inactive Count Overall = 
CALCULATE(
	[Inactive Count],
	FILTER(
		ALLSELECTED('dtCalendar'[Date]),
		ISONORAFTER('dtCalendar'[Date], MAX('dtCalendar'[Date]), DESC)
	)
)


Active Employee =
CALCULATE (
    [Joining Count],
    FILTER (
        ALLSELECTED ( 'dtCalendar'[Date] ),
        ISONORAFTER ( 'dtCalendar'[Date], MAX ( 'dtCalendar'[Date] ), DESC )
    )
) - [Inactive Count Overall]

 

Following is the output table:

 

Capture3.JPG

 

You may find the solution file here

 

Regards,
Vivek

If it helps, please mark it as a solution

Kudos would be a cherry on the top 🙂

https://www.vivran.in/

Anonymous
Not applicable

Thanks. You mention "You do need to create a separate table for Year". However, I can't find where you are making use of this table in your measures.

@Anonymous 

 

This is in reference to the additional table you had mentioned in your orignal post:

 

(3) Table (MthYrTXT) which has 2 columns, namely date and LastDayDate

 

I have not used it in my calculation. These additional columns (Year, Month, QTR) can be used for filtering the visuals. For calculation, we just need Date column.

 

Hope this answers your query.

 

Regards,
Vivek

If it helps, please mark it as a solution

Kudos would be a cherry on the top 🙂

https://www.vivran.in/

amitchandak
Super User
Super User

Please refer to my article on the same line: https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Connect on Linkedin

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.