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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
DanCasSan
Helper V
Helper V

Perform an average per month and class

Dear,
I am trying to calculate the average amount for "n" years and months, as shown in the image attached. However, I have not found any right way to do it. Any advice or trick you can give me?

 

Thank you!

Regards,

 

Media.JPG

 

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @DanCasSan 

 

Based on your description, I created data to reproduce your scenario.

Table:

d1.png

Calendar:

Calendar = CALENDARAUTO()

 

There is a one-to-many relationship between two tables. I create a 'Month-Year' column in 'Calendar' table.

Month-Year = 
IF(
    MONTH('Calendar'[Date])<10,
    YEAR('Calendar'[Date])&"0"&MONTH('Calendar'[Date]),
    YEAR('Calendar'[Date])&MONTH('Calendar'[Date])

)

 

You may create a measure as follows.

Average = 
IF(
    ISFILTERED('Calendar'[Month-Year]),
    BLANK(),
    DIVIDE(
        CALCULATE(
            SUM('Table'[Value]),
            ALL('Calendar'[Month-Year])
        ),
        CALCULATE(
            DISTINCTCOUNT('Calendar'[Month-Year]),
            ALLSELECTED('Calendar')
        )    
    )
)

 

Result:

d2.png

If I misunderstand your thoughts, please show us your expected result and sample data. Do mask sensitive data before uploading. Thanks

 

Best Regards

Allan

 

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

View solution in original post

6 REPLIES 6
v-alq-msft
Community Support
Community Support

Hi, @DanCasSan 

 

Based on your description, I created data to reproduce your scenario.

Table:

d1.png

Calendar:

Calendar = CALENDARAUTO()

 

There is a one-to-many relationship between two tables. I create a 'Month-Year' column in 'Calendar' table.

Month-Year = 
IF(
    MONTH('Calendar'[Date])<10,
    YEAR('Calendar'[Date])&"0"&MONTH('Calendar'[Date]),
    YEAR('Calendar'[Date])&MONTH('Calendar'[Date])

)

 

You may create a measure as follows.

Average = 
IF(
    ISFILTERED('Calendar'[Month-Year]),
    BLANK(),
    DIVIDE(
        CALCULATE(
            SUM('Table'[Value]),
            ALL('Calendar'[Month-Year])
        ),
        CALCULATE(
            DISTINCTCOUNT('Calendar'[Month-Year]),
            ALLSELECTED('Calendar')
        )    
    )
)

 

Result:

d2.png

If I misunderstand your thoughts, please show us your expected result and sample data. Do mask sensitive data before uploading. Thanks

 

Best Regards

Allan

 

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

You're the best! It worked perfectly.

 

Regards,

Daniel Castillo

amitchandak
Super User
Super User

Prefer to have date table with month year

 

AVERAGEX(summarize(Table,table[Month year],"_sum", SUM ( Table[Amount] )),"_sum")
AVERAGEX(values(table[Month year]),"_sum", SUM ( Table[Amount] )),"_sum")

AVERAGEX(summarize(Table,Date[Month year],"_sum", SUM ( Table[Amount] )),"_sum")
AVERAGEX(values(Date[Month year]),"_sum", SUM ( Table[Amount] )),"_sum")

 

Also refer :https://community.powerbi.com/t5/Desktop/SUM-of-AVERAGE/td-p/197013

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hello, thank you for your prompt response, I have done the following (attached code), but, it gives me the general average and, that is not what I need; what I need is that this average be based on period, storage and code as is to the image I put at the beginning.

 

SUMAVERA =
AVERAGEX(
SUMMARIZE(
DS_MPSMRP,
DS_MPSMRP[PERIODO],
DS_MPSMRP[PLWRK],
DS_MPSMRP[MATNR],
"AVERASUM",CALCULATE(SUM(DS_MPSMRP[MENGE]),FILTER(DS_MPSMRP,DS_MPSMRP[BWART]="261"))
),
[AVERASUM]
)

The formula seems fine as per the screenshot shared.

Can you share sample data and sample output. If possible please share a sample pbix file after removing sensitive information.Thanks.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
danextian
Super User
Super User

Hi @DanCasSan ,

Try this:

Average =
AVERAGEX ( VALUES ( 'Table'[YYYYMM] ), SUM ( 'Table'[Amount] ) )




Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

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.

Top Solution Authors
Top Kudoed Authors