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
Trostis
Frequent Visitor

Calculating the daily average of the displayed range when some dates have no data.

Hi folks,

 

I have a simple matrix visual showing the daily total of some production metric grouped per categories; I use a slicer to select any date range; some categories have data all days, while others don't. I want to get the average for the displayed range in the visual, no matter if the column has values for all rows; so if I'm displaying 7 days, all totals should be divided by 7. Cannot get that to work and always get the average of the existing rows in each category; so if all rows have data the result is correct (green circles), but if some date has no production, the result is wonrg (red circle). Any suggestions?

 

I'm using

AVG =
AVERAGEX(
    KEEPFILTERS(VALUES('Table'[Día Operativo])),
    CALCULATE(SUM('Table'[Product]))
)

 

Thanks and regards.

Trostis_3-1669055549497.png

1 ACCEPTED SOLUTION

Hi @Trostis 

please use

AVG =
AVERAGEX (
KEEPFILTERS (
CALCULATETABLE ( VALUES ( 'Table'[Día Operativo] ), ALL ( 'Table'[Category] ) )
),
COALESCE ( CALCULATE ( SUM ( 'Table'[Product] ) ), 0 )
)

View solution in original post

5 REPLIES 5
tamerj1
Super User
Super User

Hi @Trostis 

please try

AVG =
AVERAGEX (
KEEPFILTERS ( VALUES ( 'Table'[Día Operativo] ) ),
COALESCE ( CALCULATE ( SUM ( 'Table'[Product] ) ), 0 )
)

Thanks @tamerj1, but no luck...same result. No changes at all that I can see when applying your recommendation. Regards.

Hi @Trostis 

please use

AVG =
AVERAGEX (
KEEPFILTERS (
CALCULATETABLE ( VALUES ( 'Table'[Día Operativo] ), ALL ( 'Table'[Category] ) )
),
COALESCE ( CALCULATE ( SUM ( 'Table'[Product] ) ), 0 )
)

Excellent!!! That did work as I needed it!!! Now I'm exceeding myself with this, I know, but what the heck is that expression doing? At least the new CALCULATETABLE part...again, really appreciate your help. Regards.

@Trostis 

I didn't pay much attention at the first time. I dodn't notice that you are slicing by Category at the columns of your matrix. Which means the values are not just blank, rather they do not exist. 
in your example, the iteration table VALUES ( 'Table'[Día Operativo] ) contains only two rows. In order to iterate over all of the 6 rows we need to calculate the same table but for all the categories becuase category A contains only two rows but all the categories contain all of the 6 rows. Therefore, AVERAGEX will sum the existing two values + 0 for the nonexisting onse then divide over 6

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.