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
Chandrashekar
Resolver III
Resolver III

Average based on NMonth vs Month

Hello Team,

 

I need help with dax to get Average however I got it for count(Dax).

 

I need dax for average for below

average_Lmonth = Last Nmonth -1(Jan-24, Feb-24, Mar-24, Apr-24).

average =  Lmonth(Jan-24, Feb-24, Mar-24, Apr-24,May-24)

 

Folder: Sample File 

 

Regards,

Chandrashekar B

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Chandrashekar 

 

Thanks for the reply from @BeaBF . The following is my testing for your reference.

 

I added some data in the table.

vxuxinyimsft_1-1718008717690.png

 

 

 

Measure = 
VAR _Last1month =
    CALCULATE (
        COUNT ( 'Table'[Company] ),
        FILTER (
            'Table',
            [Month_Year] >= MIN ( slicer[Month_Year] )
                && [Month_Year]
                    <= DATE ( YEAR ( MAX ( slicer[Month_Year] ) ), ( MONTH ( MAX ( slicer[Month_Year] ) ) - 1 ), DAY ( MAX ( slicer[Month_Year] ) ) )
        )
    )
VAR _lastmonth =
    CALCULATE (
        COUNT ( 'Table'[Company] ),
        FILTER (
            'Table',
            [Month_Year] >= MIN ( slicer[Month_Year] )
                && [Month_Year] <= MAX ( slicer[Month_Year] )
        )
    )
RETURN
    DIVIDE ( _Last1month, _lastmonth )

 

 

 

Output:

vxuxinyimsft_2-1718008886130.png

 

Due to Security Policy, I am unable to open your link. If there is still a problem, please let me know the logic for calculating your desired result.

 

Best Regards,
Yulia Xu

 

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

10 REPLIES 10
BeaBF
Super User
Super User

@Chandrashekar Hi! Try with:

Average_Last_N_Months =
VAR CurrentDate = MAX('Sheet1'[Month_Year])
VAR LastNMonths = DATESINPERIOD(
    Sheet1[Month_Year],
    EOMONTH(CurrentDate, -1), -- End of last month
    -4, -- Last 4 months excluding the current month
    MONTH
)
RETURN
AVERAGEX(
    CALCULATETABLE(
        VALUES('Sheet1'),
        LastNMonths
    ),
    'Sheet1'[min_count]
)
 
Average_Current_Period =
VAR CurrentDate = MAX('Sheet1'[Month_Year])
VAR CurrentPeriod = DATESINPERIOD(
    Sheet1[Month_Year],
    CurrentDate,
    -4, -- Last 5 months including the current month
    MONTH
)
RETURN
AVERAGEX(
    CALCULATETABLE(
        VALUES('Sheet1'),
        CurrentPeriod
    ),
    'Sheet1'[min_count]
)

Hello,

 

Sorry not getting expected output. Expected out as below. Thanks in advance.

                                                                         

Output:

Chandrashekar_3-1717409210885.png

 

Input:

Chandrashekar_1-1717409099704.png

Regadrds,

Chandrashekar B

@Chandrashekar Try:

Average_Feb24_to_Apr24 =
CALCULATE(
    AVERAGE('Table'[SI NO]),
    FILTER(
        'Table',
        'Table'[Month_Year] IN {"feb-24", "mar-24", "apr-24"}
    )
)
 
Average_Feb24_to_Apr24_May24 =
CALCULATE(
    AVERAGE('Table'[SI NO]),
    FILTER(
        'Table',
        'Table'[Month_Year] IN {"feb-24", "mar-24", "apr-24", "may-24"}
    )
)
 

Hello,

 

Month should be dynamic. 

 

Regards,

Chandrashekar B

@Chandrashekar ok, dynamic based on? selection? last solar month? 

BBF

Hello,

 

Depends on selection from slicer. it may be old data(May be 2018 to till today. 

Final Intention is to check how client is doing.

Regards,

Chandrashekar B

 

Regards,

Chandrashekar B  

@Chandrashekar 

 

Average_Selected_Range =
VAR SelectedMonthss = VALUES('Table'[Month_Year])
RETURN
CALCULATE(
    AVERAGE('Table'[SI NO]),
    FILTER(
        'Table',
        'Table'[Month_Year] IN SelectedMonthss
    )
)
 
Average_Previous_Range =
VAR SelectedMonths = VALUES('Table'[Month_Year])
VAR MaxMonth = MAX('Table'[Month_Year])
VAR PreviousMonths = EXCEPT(SelectedMonths, {MaxMonth})
RETURN
CALCULATE(
    AVERAGE('Table'[SI NO]),
    FILTER(
        'Table',
        'Table'[Month_Year] IN PreviousMonths
    )
)

Hello,

 

Can we take average based on company instead of sl no.

 

Regards,

Chandrashekar B

Anonymous
Not applicable

Hi @Chandrashekar 

 

Thanks for the reply from @BeaBF . The following is my testing for your reference.

 

I added some data in the table.

vxuxinyimsft_1-1718008717690.png

 

 

 

Measure = 
VAR _Last1month =
    CALCULATE (
        COUNT ( 'Table'[Company] ),
        FILTER (
            'Table',
            [Month_Year] >= MIN ( slicer[Month_Year] )
                && [Month_Year]
                    <= DATE ( YEAR ( MAX ( slicer[Month_Year] ) ), ( MONTH ( MAX ( slicer[Month_Year] ) ) - 1 ), DAY ( MAX ( slicer[Month_Year] ) ) )
        )
    )
VAR _lastmonth =
    CALCULATE (
        COUNT ( 'Table'[Company] ),
        FILTER (
            'Table',
            [Month_Year] >= MIN ( slicer[Month_Year] )
                && [Month_Year] <= MAX ( slicer[Month_Year] )
        )
    )
RETURN
    DIVIDE ( _Last1month, _lastmonth )

 

 

 

Output:

vxuxinyimsft_2-1718008886130.png

 

Due to Security Policy, I am unable to open your link. If there is still a problem, please let me know the logic for calculating your desired result.

 

Best Regards,
Yulia Xu

 

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

Hello,

 

Thank you and will check.

 

Regards,

Chandrashekar B

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.