Forum Discussion
Anonymous
3 years agoNot applicable
How to store the values or While loop.
HI All... I have Date and employee code columns. i need to store the count of the employees for last 12 months for each month. EX: Last 12 months logic From to Aug-23 From Aug-23 to ...
rubayatyasmin
3 years agoCommunity Champion
Hi, Anonymous
Create a Date table first then create a relationship with the date tables date column and employee tables date column. Then use DATESINPERIOD() dax func.
For instance,
CALCULATE( COUNT('Employees'[employee_code]), DATESINPERIOD('DateTable'[Date], MAX('DateTable'[Date]), -12, MONTH) )
refer: https://learn.microsoft.com/en-us/dax/datesinperiod-function-dax
or you can use DATESBETWEEN().
refer: https://radacad.com/datesinperiod-vs-datesbetween-dax-time-intelligence-for-power-bi