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
PowerAuto82
Helper II
Helper II

%Turnover over a Range of Months

Hi,

 

I currently have the following DAX Calulcations Termination and Headcount to work out the % Turnover

 

Terminations =

CALCULATE(
COUNT('Fact'[Emp Id]),
USERELATIONSHIP('Fact'[Employment End Date],Dates[Date]),
NOT(ISBLANK('Fact'[Employment End Date])),
'Fact'[Employment End Date] <= TODAY()

)+0



Headcount =
CALCULATE(
COUNTX(
FILTER('Fact','Fact'[Employment Start Date]<=MAX('Dates'[Date])
&&
(ISBLANK('Fact'[Employment End Date])
|| 'Fact'[Employment End Date]>MAX(Dates[Date]))),
'Fact'[Personnel Number]),ALL('Termination Category'[Termination Category])
) + 0

 

% Turnover = 
    VAR _Headcount =
	
CALCULATE(
    COUNTX(
        FILTER('Fact','Fact'[Employment Start Date]<=MAX('Dates'[Date]) 
        &&
        (ISBLANK('Fact'[Employment End Date]) 
        || 'Fact'[Employment End Date]>MAX(Dates[Date]))),
        'Fact'[Personnel Number]),ALL('Termination Category'[Termination Category])
        ) + 0


	VAR _AvgHeadcount =

AVERAGEX(
       VALUES(Dates[Date]),
        [Headcount]
        ) + 0


	VAR _Turnover =

DIVIDE('Calculations'[Terminations],_AvgHeadcount,BLANK())

RETURN
	_Turnover

 

But if the end user selects the Year = 2022 and Month = July I want to see the % Turnover on average over the previous 12 months i.e 01/08/2022 to 31/07/2022

 

other examples of date range to return if they select the highlighted Month Year dates

 

June 2022 (should display turnover from 01/07/2021 to 30/06/2022)

May 2022 (should display turnover from 01/06/2021 to 31/05/2022)

April 2022 (should display turnover from 01/05/2021 to 30/04/2022)

 

Thanks

 

2 REPLIES 2
PowerAuto82
Helper II
Helper II

Hi @v-yangliu-msft Thanks for your reply, just look at your example and not sure if it is working because when selecting the different Month or Years the adjacent table would not show the dates within that date range, all dates are showing

v-yangliu-msft
Community Support
Community Support

Hi  @PowerAuto82 ,

I created some data:

vyangliumsft_0-1662517392869.png

Here are the steps you can follow:

1. Create calculated table.

Date =
DISTINCT('Table1'[Date])

vyangliumsft_1-1662517392873.png

Create caluculated column.

Year = YEAR('Date'[Date])
Month = MONTH('Date'[Date])

vyangliumsft_2-1662517392874.png

2. Create measure.

Flag =
var _year=SELECTEDVALUE('Date'[Year])
var _month=SELECTEDVALUE('Date'[Month])
var _start=
    DATE(
        _year,_month-11,1)
var _end=
EOMONTH(
    DATE(
        _year,_month,1),0)
return
AVERAGEX(FILTER(ALL(Table1),
'Table1'[Date]>=_start&&'Table1'[Date]<=_end),[Sales])

3. Result:

vyangliumsft_3-1662517392879.png

If you need pbix, please click here.

%Turnover over a Range of Months.pbix

If this method can't meet your requirement, can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the 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.