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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
quyenduong
Helper II
Helper II

12M Rolling Metrics - DAX code - How to exclude the first 11 months

Dear community,

 

I have the following is DAX code in Power BI to calculate the Rolling 12 Attrition Rate = (sum of leavers in the last 12 months) / Average Headcount in the last month and it works properly:

 

Rolling 12M Attrition Rate =

VAR __NrOfRollingMonths = 12

VAR __CurrentDate = MAX ( 'Date Table'[Date] )

VAR __RollingMonths =

       FILTER (

            ALL ( 'Date Table' ), 'Date Table'[Date] > EDATE ( __CurrentDate, - __NrOfRollingMonths )

                 && 'Date Table'[Date] <= __CurrentDate

)

RETURN

       CALCULATE ( DIVIDE([Voluntary Leavers], AVERAGEX(VALUES('Date Table'[Report Month]),[Headcount Permanent Contract])), __RollingMonths )

 

However, for the first 11 months, it give very small % of Attrition because it doesnt have data of previous 12M (see red collumn).

quyenduong_0-1681897878170.png

(these numbers in the screenshot are modified and fictional, the screenshot is just to show the ideal outcome)


From the Date column from Date Table, how can we edit the DAX above to achieve the green column that:

- It calculates exactly the same logic

- Based on the column Date from Date Table, can you please give Attrition Rate blank for the first 11 months of the data, (the Date column from Date Table is everyday from January 2021 till March 2023) so I want from Jan 2021 till November 2021, the Attrition rate is blank

 

I tried several ways to edit this code but it doesnt work.  Thank you in advance for your answer. 

1 REPLY 1
v-shex-msft
Community Support
Community Support

HI @quyenduong,

You can add a variable to get the first date from current table records with filter effects, then you can package expression with if statement and use this variable as condition to compare with current axis date and skip the calculations if current date is included in the first 11 months.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.