Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Dynamic date sort for last n year

Hi,

 

Please find the attachment of sample data and do the needful.

I have two date fields in separation page . namely Date of Joining Field and Exit Date . I nee dthe logic like 

 Count of Employees are who are joined before “Date of Joining” and “Exit Date” greater than given “Date of Joining” Example: Start Date = 01/01/2019 and End Date = 03/01/2020 i.e., Separation = Count of Employees “Date of joining” before 01/01/2019 & Exit Date greater than 01/01/2019

 

For this I have used a DAX with the support of community as 

Last Period Employee =
var _min_date = minx(all('Calendar'),'Calendar'[Date])
var _Expression=if(ISFILTERED('CALENDAR'[Month Year]),maxx('CALENDAR',ENDOFMONTH(DATEADD('CALENDAR'[Date],-1,MONTH))),maxx('CALENDAR',DATEADD('CALENDAR'[Date],-1,YEAR)))
Return
CALCULATE(COUNTx(FILTER(Separation,Separation[Date of joining]<=_Expression && Separation[Date of joining]>=_min_date && (ISBLANK(Separation[Exit Date]) || Separation[Exit Date]>_Expression)),(Separation[Employee ID])),CROSSFILTER(Separation[Date of joining],'CALENDAR'[Date],None))

 

 

and it is working good but it is showing for last one year from today and if i need to check for last 2 years i need to change -1 to -2 so on but i need the same logic dynamically whenever i sort date range and i taken a calendar table as below and given realtionship to Calendar [date] to separation [date of joining] and separation[exit date]

Please do the needful as i have struck in this logic since 3 days & i am trying to attach a dummy data but i didnt notice any option here can anyone suggest me.

3 Replies