Forum Discussion
DAX: filter a date column based on specific dates from another Table
- 6 years ago
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/
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:
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)
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:
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/
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.
- vivran226 years ago
Community Champion
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/