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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Bfaws
Helper III
Helper III

Average employee count previous 12 months

 

Hello, 

 

I hope someone can help.  I have a measure below which looks at adding the employee headcount for each month in the previous 12 months and gives an average.  I`m trying figure out another measure which will give the result below but at the previous month or if I add a filter the previous 12 months at a specific time.  For example January 2021 would be previous 12 months from January 2021, and another to show December 2020 which would show previous 12 months starting from December.  This wouls allow me to compare two months to see if the overall employee average number has increased or decreased.

 

Thanks in advance for any help.

 

Brendan

Av. Employees = 
var __periodInQuestion = 
    DATESINPERIOD(
        Rolling_Calendar_Lookup[Date],
        MAX( Rolling_Calendar_Lookup[Date] ),
        -12, 
        MONTH
    )
var __result =
    AVERAGEX(
        __periodInQuestion,
        [Total FTE]
    )
return
    __result

 

 

1 ACCEPTED SOLUTION

Hi @Bfaws 

I think you want to compare two values.

The first one is the average of the sum of  headcount in rolling 12 months before the month you select by month.

The second one is the average of the sum of headcount in rolling 12 months before the month you select -1 by month.

Due to I don't know your data model, I build a sample to have a test.

I add a YearMonth column for calculating.

YearMonth = YEAR(Sheet46[Date])*100+MONTH(Sheet46[Date])

1.png

Date Table:

Rolling_Calendar_Lookup = CALENDARAUTO()
AvSel = 
VAR _Sel = MAX(Rolling_Calendar_Lookup[Date])
VAR _Sel_Max = EOMONTH(_Sel,0)
VAR _Sel_Min = EOMONTH(_Sel,-12)+1
VAR _Total = SUMX(FILTER(ALL(Sheet46),Sheet46[Date]>=_Sel_Min&&Sheet46[Date]<=_Sel_Max),Sheet46[Value])
VAR _CountMonth = CALCULATE(DISTINCTCOUNT(Sheet46[YearMonth]),FILTER(ALL(Sheet46),Sheet46[Date]>=_Sel_Min&&Sheet46[Date]<=_Sel_Max))
Return
DIVIDE(_Total,_CountMonth)
AvSelLastMonth = 
VAR _Sel = MAX(Rolling_Calendar_Lookup[Date])
VAR _Sel_Max = EOMONTH(_Sel,-1)
VAR _Sel_Min = EOMONTH(_Sel_Max,-12)+1
VAR _Total = SUMX(FILTER(ALL(Sheet46),Sheet46[Date]>=_Sel_Min&&Sheet46[Date]<=_Sel_Max),Sheet46[Value])
VAR _CountMonth = CALCULATE(DISTINCTCOUNT(Sheet46[YearMonth]),FILTER(ALL(Sheet46),Sheet46[Date]>=_Sel_Min&&Sheet46[Date]<=_Sel_Max))
Return
DIVIDE(_Total,_CountMonth)

Result is as below.

130/12 = 10.83 is the average of sum of headcount ranged by (2019/02/01-2020/01/31 the rolling 12 month)

121/12 = 10.08 is the average of sum of headcount ranged by (2019/01/01-2019/12/31 the rolling 12 month)

 

1.png

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

 

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Bfaws , Try like

 

AvgPrv12Months =
divide( CALCULATE([Total FTE],DATESINPERIOD('DateTable'[Date ],MAX('DateTable'[Date]),-12,MONTH)) ,
CALCULATE(distinctCOUNT('DateTable'[Month Year]),DATESINPERIOD('DateTable'[Date],MAX('DateTable'[Date]),-12,MONTH), filter(Table, not(isblank([Toatl FTE])))))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@amitchandak 

 

Thanks for the reply.

 

I`ve not been able to replicate this.  I`ve ammended the measure above to suit my date table but not sure about highlighted part of measure - you refer to Table but i`m not sure what you mean here. Thanks.

 

AvgPrv12Months =
divide( CALCULATE([Total FTE],DATESINPERIOD('DateTable'[Date ],MAX('DateTable'[Date]),-12,MONTH)) ,
CALCULATE(distinctCOUNT('DateTable'[Month Year]),DATESINPERIOD('DateTable'[Date],MAX('DateTable'[Date]),-12,MONTH), filter(Table, not(isblank([Toatl FTE])))))

Hi @Bfaws 

I think you want to compare two values.

The first one is the average of the sum of  headcount in rolling 12 months before the month you select by month.

The second one is the average of the sum of headcount in rolling 12 months before the month you select -1 by month.

Due to I don't know your data model, I build a sample to have a test.

I add a YearMonth column for calculating.

YearMonth = YEAR(Sheet46[Date])*100+MONTH(Sheet46[Date])

1.png

Date Table:

Rolling_Calendar_Lookup = CALENDARAUTO()
AvSel = 
VAR _Sel = MAX(Rolling_Calendar_Lookup[Date])
VAR _Sel_Max = EOMONTH(_Sel,0)
VAR _Sel_Min = EOMONTH(_Sel,-12)+1
VAR _Total = SUMX(FILTER(ALL(Sheet46),Sheet46[Date]>=_Sel_Min&&Sheet46[Date]<=_Sel_Max),Sheet46[Value])
VAR _CountMonth = CALCULATE(DISTINCTCOUNT(Sheet46[YearMonth]),FILTER(ALL(Sheet46),Sheet46[Date]>=_Sel_Min&&Sheet46[Date]<=_Sel_Max))
Return
DIVIDE(_Total,_CountMonth)
AvSelLastMonth = 
VAR _Sel = MAX(Rolling_Calendar_Lookup[Date])
VAR _Sel_Max = EOMONTH(_Sel,-1)
VAR _Sel_Min = EOMONTH(_Sel_Max,-12)+1
VAR _Total = SUMX(FILTER(ALL(Sheet46),Sheet46[Date]>=_Sel_Min&&Sheet46[Date]<=_Sel_Max),Sheet46[Value])
VAR _CountMonth = CALCULATE(DISTINCTCOUNT(Sheet46[YearMonth]),FILTER(ALL(Sheet46),Sheet46[Date]>=_Sel_Min&&Sheet46[Date]<=_Sel_Max))
Return
DIVIDE(_Total,_CountMonth)

Result is as below.

130/12 = 10.83 is the average of sum of headcount ranged by (2019/02/01-2020/01/31 the rolling 12 month)

121/12 = 10.08 is the average of sum of headcount ranged by (2019/01/01-2019/12/31 the rolling 12 month)

 

1.png

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

 

This is great and replicated exactly as expected. 

 

Many thanks.

 

Brendan

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.