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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Salva71
New Member

Calculate subtotals average of columns

Hello -

 

Bewing new to Power Pivot and not familiar with DAX, I would appreciate some help with this task:

 

I have a dataset of production costs by product number, work order number, and facility. I need to display the average cost of all work orders at a given facility and for a given product on a table. Is there a DAX formula that can help me do that? Below is a screenshot of my pivot, in which the subtotal and Grand Total show sums instead of averages (my intended result).  

 

Thank you for your help!

 

Salva

 

Salva71_0-1741527441751.png

 

1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @Salva71 ,

 

You can calculate the average cost of all work orders at a given facility and for a given product using the AVERAGEX function in DAX. This function iterates over a table and evaluates an expression for each row, returning the average. The formula to use is:

 

Average Cost = AVERAGEX(
    VALUES('YourTable'[Work Order Number]), 
    CALCULATE(SUM('YourTable'[Cost/Case]))
)

 

In this formula, VALUES('YourTable'[Work Order Number]) retrieves the unique work orders in the current filter context, ensuring that the calculation considers each work order separately. The CALCULATE(SUM('YourTable'[Cost/Case])) ensures that for each work order, the total cost is summed up correctly before being averaged. AVERAGEX then computes the final average across all work orders.

To apply this in your Power Pivot table, create a new measure using the formula above and use it in your pivot table instead of the current sum aggregation. If needed, ensure that the aggregation type in the Values area is set to Average. This will display the correct average cost rather than summing up the costs, which is the issue in your current pivot table setup. Let me know if you need further clarification!

 

Best regards,

View solution in original post

2 REPLIES 2
DataNinja777
Super User
Super User

Hi @Salva71 ,

 

You can calculate the average cost of all work orders at a given facility and for a given product using the AVERAGEX function in DAX. This function iterates over a table and evaluates an expression for each row, returning the average. The formula to use is:

 

Average Cost = AVERAGEX(
    VALUES('YourTable'[Work Order Number]), 
    CALCULATE(SUM('YourTable'[Cost/Case]))
)

 

In this formula, VALUES('YourTable'[Work Order Number]) retrieves the unique work orders in the current filter context, ensuring that the calculation considers each work order separately. The CALCULATE(SUM('YourTable'[Cost/Case])) ensures that for each work order, the total cost is summed up correctly before being averaged. AVERAGEX then computes the final average across all work orders.

To apply this in your Power Pivot table, create a new measure using the formula above and use it in your pivot table instead of the current sum aggregation. If needed, ensure that the aggregation type in the Values area is set to Average. This will display the correct average cost rather than summing up the costs, which is the issue in your current pivot table setup. Let me know if you need further clarification!

 

Best regards,

It worked perfectly! Thank you, DataNinja777 🙏

 

May I ask this community where to find good training material on DAX?

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.