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! Learn more

Reply
Szwadron
Frequent Visitor

Average for table depending on number of months displayed

Hi everyone, 

I am struggling to find an appropriate measure code that I could use in a card visualisation that would show me average of displayed values per month.

 

YearJanuaryFebruaryMarchAprilMayJuneJulyAugustSeptember
2021100110120130140150160170180
2022250260270280290300310320330
2023360370380400420430480  

 

So let's say I have a table like above that is calculated based on Costs table from my data model and I would like to be able to select the entire row by clicling on the right year and a card visualisation would show me average of selected period. But here is the problem I have that I cannot just divide by 12 months since for current year I only have data till current month so:
1) for all previous years it should be divided by 12 months
2) for current year by numbers of months that appear in my data model

or in another words I would like to divide values that are shown in a table by numer of columns in a table including when value is 0 and excluding blanks.

Is that achievable with a measure or I need to use calculated column?

I would really apprecaite your hints.

 

Thank you in advance

2 ACCEPTED SOLUTIONS
johnt75
Super User
Super User

If the measure you are using in the visual is [Costs] then you could use

Avg Costs =
AVERAGEX ( SUMMARIZE ( 'Date', 'Date'[Year month] ), [Costs] )

If no year is selected it will show the average over all time. If a year is selected then it will show the average for that year.

View solution in original post

MAwwad
Solution Sage
Solution Sage

 

You can create a measure that calculates the number of months displayed in the table and use it to calculate the average. Here's an example measure:

 

 
Avg Cost = VAR NumOfMonths = COUNTAX( FILTER( ALLSELECTED( Dates ), NOT(ISBLANK( [YourCostMeasure] )) ), [Month] ) RETURN DIVIDE( [YourCostMeasure], NumOfMonths )
 

Replace [YourCostMeasure] with your cost measure, and [Month] with the column that contains the month information in your date table.

The measure first calculates the number of months displayed in the table by counting the non-blank columns for the selected year. It then divides the cost measure by the number of months displayed.

In the visual, you can select the year to display and the measure should calculate the average based on the number of non-blank months in the selected year.

View solution in original post

2 REPLIES 2
MAwwad
Solution Sage
Solution Sage

 

You can create a measure that calculates the number of months displayed in the table and use it to calculate the average. Here's an example measure:

 

 
Avg Cost = VAR NumOfMonths = COUNTAX( FILTER( ALLSELECTED( Dates ), NOT(ISBLANK( [YourCostMeasure] )) ), [Month] ) RETURN DIVIDE( [YourCostMeasure], NumOfMonths )
 

Replace [YourCostMeasure] with your cost measure, and [Month] with the column that contains the month information in your date table.

The measure first calculates the number of months displayed in the table by counting the non-blank columns for the selected year. It then divides the cost measure by the number of months displayed.

In the visual, you can select the year to display and the measure should calculate the average based on the number of non-blank months in the selected year.

johnt75
Super User
Super User

If the measure you are using in the visual is [Costs] then you could use

Avg Costs =
AVERAGEX ( SUMMARIZE ( 'Date', 'Date'[Year month] ), [Costs] )

If no year is selected it will show the average over all time. If a year is selected then it will show the average for that year.

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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