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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
psstack
New Member

DAX coding help for average FTE calculation

Hi All,

I have been tryiong to develop a measure that will calculate the avgFTE over a selected period of time, but have not been able to get it to calculate correctly.  The code I have works for months Feb-Dec and Q2-Q4, but does not work for Jan, Q1 or Full year averages where the calculation has to span to the prior year.  The logic for calculating avg FTE for a specific month is the average of the ending FTE for that month and the prior month.  For the qtr it is the average of the ending FTEs for the 3 months of the selected qtr and the last month of the prior qtr.  And for full year it is the average of the ending FTE for each month of the selected year and Dec of the prior year.   

 

Below is the code I have written as well as a snippet from my dashboard.  Can anyone help in fixing this code or writing a new code that would work for this calculation? 

 

psstack_0-1756148016572.png

 


Avg_FTE =

VAR sQtr =
    SELECTEDVALUE ( Periods[Qtr] )
VAR sMonth =
    SELECTEDVALUE ( Periods[Month Name] )
VAR sYear =
    SELECTEDVALUE ( Periods[Year] )
VAR sDate =
    MAX ( Periods[Period (dt)] )
VAR sEndMonth =
    EOMONTH ( sDate0 )
VAR maxYear =
    CALCULATE ( MAX ( Periods[Year] ), REMOVEFILTERS ( Periods ) )
VAR maxDate =
    CALCULATE ( MAX ( Periods[Period (dt)] ), REMOVEFILTERS ( Periods ) )
VAR NewEndofMonth =
    SWITCH (
        TRUE (),
        sYear
            == maxYear && ISBLANK ( sMonth )
                && ISBLANK ( sQtr ), maxDate,
        sYear
            == maxYear && ISBLANK ( sMonth )
                && sQtr = "Q4"maxDate,
        sYear
            == maxYear
                && NOT ( ISBLANK ( sMonth ) )
                    && sMonth = "Dec"maxDate,
        sEndMonth
    )
VAR sQtrCal =
    CALCULATE (
        [FTEs],
        DATESINPERIOD ( Periods[Period (dt)]NewEndofMonth, -4MONTH ),  
        REMOVEFILTERS ( Periods )
    )
VAR sYearCal =
    CALCULATE (
        [FTEs],
        DATESINPERIOD ( Periods[Period (dt)]NewEndofMonth, -13MONTH ),  //Master_Data[SCENARIO] in {"ACTUAL", "M5_Forecast"},
        REMOVEFILTERS ( Periods )
    )
VAR sMonthCal =
    CALCULATE (
        [FTEs],
        DATESINPERIOD ( Periods[Period (dt)]NewEndofMonth, -2MONTH ),  //Master_Data[SCENARIO] in {"ACTUAL", "M5_Forecast"},
        REMOVEFILTERS ( Periods )
    )
VAR FirstMonthCalcPY =
    CALCULATE (
        [FTEs],
        DATESINPERIOD ( Periods[Period (dt)]NewEndofMonth, -2MONTH ),  Master_Data[Submission] in {"PY_ACTUAL"} || Master_Data[SCENARIO] in {"ACTUAL"},
        REMOVEFILTERS ( Periods )
    )

VAR FirstMonthCalcPY_Qtr =
    CALCULATE (
        [FTEs],
        //Periods[Period] = "202412",Master_Data[SCENARIO] in {"ACTUAL"}    
        DATESINPERIOD ( Periods[Period (dt)]NewEndofMonth, -4MONTH ),  Master_Data[Submission] in {"PY_ACTUAL"} || Master_Data[SCENARIO] in {"ACTUAL"},
        REMOVEFILTERS ( Periods )
    )

VAR LastMonthPY =
    CALCULATE (
        [FTEs],
        DATESINPERIOD ( Periods[Period (dt)]NewEndofMonth, -13MONTH ),  Master_Data[Submission] in {"PY_ACTUAL"} || Master_Data[SCENARIO] in {"ACTUAL"},
        REMOVEFILTERS ( Periods )
    )
VAR FirstMonthCalcCY =
    CALCULATE (
        [FTEs],
        DATESINPERIOD ( Periods[Period (dt)]NewEndofMonth, -2MONTH ),
        REMOVEFILTERS ( Periods )
    )

RETURN
    SWITCH (
        TRUE (),
        ISBLANK ( sMonth ) && ISBLANK ( sQtr ) && sYear2025DIVIDE (LastMonthPY + sYearCal130 ),
        ISBLANK ( sMonth ) && ISBLANK ( sQtr ), DIVIDE ( sYearCal130 ),
        ISBLANK ( sMonth ) && sQtr = "Q1" && sYear = 2025DIVIDE(FirstMonthCalcPY_Qtr+sQtrCal,4,0),
        ISBLANK ( sMonth ), DIVIDE ( sQtrCal40 ),
        sMonth = "Jan" && sYear = 2025DIVIDE(FirstMonthCalcPY+FirstMonthCalcCY,2,0),
        DIVIDE ( sMonthCal20 )
    )
1 ACCEPTED SOLUTION
v-saisrao-msft
Community Support
Community Support

Hi @psstack,

Thank you @BeaBF,@FBergamaschi, for your insights.

I’ve reproduced your issue using sample data and confirmed the behavior. The measures are returning the expected results Ending FTE provides the final available value for the period, whereas Avg FTE Month/Quarter/Year shows the appropriate aggregation for each respective level. Ending FTE gives the last available value in the period, while the Avg FTE Month/Quarter/Year reflect the correct aggregation at each level.

vsaisraomsft_0-1756196629504.png

Hope this helps

Thank you.

View solution in original post

6 REPLIES 6
v-saisrao-msft
Community Support
Community Support

Hi @psstack,

We haven’t heard back from you in a while regarding your issue. let us know if your issue has been resolved or if you still require support.

 

Thank you.

v-saisrao-msft
Community Support
Community Support

Hi @psstack,

Checking in to see if your issue has been resolved. let us know if you still need any assistance.

 

Thank you.

v-saisrao-msft
Community Support
Community Support

Hi @psstack,

Have you had a chance to review the solution we shared earlier? If the issue persists, feel free to reply so we can help further.

 

Thank you.

v-saisrao-msft
Community Support
Community Support

Hi @psstack,

Thank you @BeaBF,@FBergamaschi, for your insights.

I’ve reproduced your issue using sample data and confirmed the behavior. The measures are returning the expected results Ending FTE provides the final available value for the period, whereas Avg FTE Month/Quarter/Year shows the appropriate aggregation for each respective level. Ending FTE gives the last available value in the period, while the Avg FTE Month/Quarter/Year reflect the correct aggregation at each level.

vsaisraomsft_0-1756196629504.png

Hope this helps

Thank you.

BeaBF
Super User
Super User

@psstack Hi! Try with:

Avg_FTE =
VAR CurrDate = MAX ( Periods[Period (dt)] )
VAR CurrYear = YEAR ( CurrDate )
VAR CurrMonth = MONTH ( CurrDate )

-- Current period FTE (month, quarter, or year context)
VAR CurrFTEs =
CALCULATE ( [FTEs], KEEPFILTERS ( Periods[Period (dt)] ) )

-- Prior month FTE (for Jan, will go to Dec prior year)
VAR PrevMonthFTE =
CALCULATE (
[FTEs],
DATEADD ( Periods[Period (dt)], -1, MONTH )
)

-- Prior quarter last month FTE (for Q1, this will go to Dec prior year)
VAR PrevQtrFTE =
CALCULATE (
[FTEs],
DATEADD ( Periods[Period (dt)], -1, QUARTER )
)

-- Prior year Dec FTE (for Full Year averages)
VAR PrevYearEndFTE =
CALCULATE (
[FTEs],
FILTER ( ALL ( Periods ), Periods[Year] = CurrYear - 1 && Periods[Month Name] = "Dec" )
)

-- Average logic
RETURN
SWITCH (
TRUE(),
-- If at Month granularity
HASONEVALUE ( Periods[Month Name] ),
DIVIDE ( PrevMonthFTE + CurrFTEs, 2 ),

-- If at Quarter granularity
HASONEVALUE ( Periods[Qtr] ),
DIVIDE ( PrevQtrFTE + SUMX ( VALUES ( Periods[Month Name] ), [FTEs] ), 4 ),

-- If at Year granularity
HASONEVALUE ( Periods[Year] ),
DIVIDE ( PrevYearEndFTE + SUMX ( VALUES ( Periods[Month Name] ), [FTEs] ), 13 )
)

BBF


💡 Did I answer your question? Mark my post as a solution!

👍 Kudos are appreciated

🔥 Proud to be a Super User!

Community News image 1920X1080.png
FBergamaschi
Solution Sage
Solution Sage

Please include, in a usable format, not an image, a small set of rows for each of the tables involved in your request and show the data model in a picture, so that we can import the tables in Power BI and reproduce the data model. The subset of rows you provide, even is just a subset of the original tables, must cover your issue or question completely. Do not include sensitive information and do not include anything that is unrelated to the issue or question. Please show the expected outcome based on the sample data you provided and make sure, in case you show a Power BI visual, to clarify the columns used in the grouping sections of the visual.

 

Need help uploading data? click here

 

Want faster answers? click here

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.