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
murphm6
Helper II
Helper II

How to take the average of rows in a matrix and sum in column header

I have a matrix visual that breaks down average cost by product name, product code, and batch code. My problem is that the avg cost values for the lot code and product code are being summed at the product name level, which is incorrect. 

 

murphm6_0-1659707626260.png

 

For example, I'd like the value for 535C11 (48919) to be the average of the batch codes below it (roughly 1.6). I'd then like to sum the averages of the 2 '535C11' values at the top level where it says 'ARISTONATE'. 

 

Average cost is being calculated like this: 

AvgCost = CALCULATE(AVERAGE('ZRAW_PROD-PKG-WHS-LOT'[Average-Cost]), filter('ZRAW_PROD-PKG-WHS-LOT', 'ZRAW_PROD-PKG-WHS-LOT'[Prod-Pkg-Code] == 'SMOG w/ Lot Code'[Prod-Pkg-Code] && 'SMOG w/ Lot Code'[Lot-Code] = 'ZRAW_PROD-PKG-WHS-LOT'[Lot-Code]))
 
Here is the relationship between the two tables. can anyone help?
 
murphm6_1-1659708012306.png

 

1 REPLY 1
lbendlin
Super User
Super User

A measure in a matrix visual is calculated four times, for the individual cells, the row totals, the column totals, and for the grand total.  You can adjust your calculation accordingly, using HASONEVALUE to figure out where in the matrix you are .

 

Please provide sanitized sample data that fully covers your issue. I cannot help you without usable sample data.
Please paste the data into a table in your post or use one of the file services like OneDrive or Google Drive. I cannot use screenshots of your source data.
Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

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.