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
Shrujan1612
Helper I
Helper I

Average headcount (current + previous month)/2

I want to calculate (current + previous month)/2
Below is the measure i am using for average calculation.

Average Current and Previous Month Headcount =
VAR SelectedDate = MAX('Presentation Calendar'[CALENDAR_DATE])

VAR PreviousMth = EDATE(SelectedDate, -1)

VAR LastDateOfPreviousMonth = EOMONTH(PreviousMth, 0)

 

VAR CurrentMonthHeadcount =

    CALCULATE(

        [TTM_headcount],

        FILTER(

            ALL('Presentation Calendar'),

            'Presentation Calendar'[CALENDAR_DATE] = SelectedDate

        )

    )

 

VAR PreviousMonthClosingHeadcount =

    CALCULATE(

        [TTM_headcount],

        FILTER(

            ALL('Presentation Calendar'),

            'Presentation Calendar'[CALENDAR_DATE] = LastDateOfPreviousMonth

        )

    )

 

VAR AverageHeadcount = DIVIDE(CurrentMonthHeadcount + PreviousMonthClosingHeadcount, 2)

 

RETURN  AverageHeadcount

Sample:
Expected output

month yearcurrent month valueprevious month valueAvg
Oct-231099.5
Nov-23111010.5
Dec-23121111.5
Jan-24131212.5
Feb-24141313.5
Mar-24151414.5
Apr-24161515.5
May-24171616.5
Jun-24181717.5
Jul-24191818.5
Aug-24201919.5
Sep-24212020.5

---------------------------
Current output:

month yearcurrent month valueprevious month value 
Oct-23101010
Nov-23111111
Dec-23121212
Jan-24131313
Feb-24141414
Mar-24151515
Apr-24161616
May-24171717
Jun-24181818
Jul-24191919
Aug-24202020
Sep-2421 10.5
1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1727590063305.png

 

 

Jihwan_Kim_0-1727590048197.png

 

Count avg: = 
SUMX (
    SUMMARIZE ( 'Calendar', 'Calendar'[Month-Year sort], 'Calendar'[Month-Year] ),
    CALCULATE (
        VAR _currentmonth =
            SUM ( data[count] )
        VAR _prevmonth =
            CALCULATE (
                SUM ( data[count] ),
                OFFSET (
                    -1,
                    ALL ( 'Calendar'[Month-Year], 'Calendar'[Month-Year sort] ),
                    ORDERBY ( 'Calendar'[Month-Year sort], ASC )
                )
            )
        RETURN
            IF ( _currentmonth && _prevmonth, DIVIDE ( _currentmonth + _prevmonth, 2 ) )
    )
)

 

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1727590063305.png

 

 

Jihwan_Kim_0-1727590048197.png

 

Count avg: = 
SUMX (
    SUMMARIZE ( 'Calendar', 'Calendar'[Month-Year sort], 'Calendar'[Month-Year] ),
    CALCULATE (
        VAR _currentmonth =
            SUM ( data[count] )
        VAR _prevmonth =
            CALCULATE (
                SUM ( data[count] ),
                OFFSET (
                    -1,
                    ALL ( 'Calendar'[Month-Year], 'Calendar'[Month-Year sort] ),
                    ORDERBY ( 'Calendar'[Month-Year sort], ASC )
                )
            )
        RETURN
            IF ( _currentmonth && _prevmonth, DIVIDE ( _currentmonth + _prevmonth, 2 ) )
    )
)

 

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
rajendraongole1
Super User
Super User

Hi @Shrujan1612 - you can modify the way the previous month is retrieved and adjust the calculation for both the current and previous months

Average Current and Previous Month Headcount =
VAR SelectedDate = MAX('Presentation Calendar'[CALENDAR_DATE])

-- Get the previous month’s date
VAR PreviousMth = EDATE(SelectedDate, -1)

-- Get the last date of the previous month
VAR LastDateOfPreviousMonth = EOMONTH(PreviousMth, 0)

-- Calculate the current month’s headcount
VAR CurrentMonthHeadcount =
CALCULATE(
[TTM_headcount],
FILTER(
ALL('Presentation Calendar'),
'Presentation Calendar'[CALENDAR_DATE] = SelectedDate
)
)

-- Calculate the headcount for the last date of the previous month
VAR PreviousMonthClosingHeadcount =
CALCULATE(
[TTM_headcount],
FILTER(
ALL('Presentation Calendar'),
'Presentation Calendar'[CALENDAR_DATE] = LastDateOfPreviousMonth
)
)

-- Calculate the average of the current and previous month’s headcounts
VAR AverageHeadcount =
DIVIDE(CurrentMonthHeadcount + PreviousMonthClosingHeadcount, 2)

RETURN
IF(
ISBLANK(CurrentMonthHeadcount) || ISBLANK(PreviousMonthClosingHeadcount),
BLANK(), -- Handle cases where either value is blank
AverageHeadcount
)

 

Hope the above modified measure helps in your scenerio





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

Proud to be a Super User!





Hi Rajendra,

Thankyou for your time.

Issue i am facing is with Previous month if you see my expected output I want previous month value in current for to sum current month + previous month but i am getting ouput as second screenshot. So, it is giving me wrong avg. And month year column i am considering from other calendar table as it required rolling 24 month .

Shrujan1612_0-1727584731788.png

 

Shrujan1612_1-1727584816330.png

 



Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.