March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe 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
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
Solved! Go to 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])
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)
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.
@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])))))
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])
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)
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
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
134 | |
91 | |
89 | |
64 | |
58 |
User | Count |
---|---|
201 | |
137 | |
107 | |
72 | |
68 |