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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
sr97
New Member

Power BI - Problem with calculating grand total for weighted average

Hi all, 

 

I'm trying to calculate a weighted average of delivery precision based on volume. Each ID (Column 1) in the table has a volume (Column 4) and a delivery precision ( Column 3). The weighted average is Column 3* Column 5 ( the weight of a volume for a given week)

sr97_1-1739883450971.png

If I sum column 6 in excel, I get a total of 0.9376 (correct answer). However, Power BI gives me a value of 160325 ( which doesn't make sense). I have tried to find a solution to this problem using both youtube and this forum, without any success.

 

This is my approach:

 

Weighted average_Delivery =

VAR _TotalVolume = CALCULATE(SUM('Data'[Volume]),ALL('Data’[ID])) // Calculating the total volume for a given week

 

VAR _Nominator = CALCULATE(SUM('Data -'[Volume])) // finding the volume for a given ID

 

VAR VolumeWeight =CALCULATE((_Nominator/_TotalVolume)) // Calculating the weight to find the weighted average

 

VAR DeliveryPrecision = CALCULATE(SUM('Data’[DeliveryPrec]),ALLEXCEPT(Calendar,Calendar[WeekNum],Calendar[Month],Calendar[Year])) // Delivery precision for an ID

 

VAR DeliveryprecisionTable = ADDCOLUMNS(SUMMARIZE('Data','Data ‘[ID],Calendar[WeekNum]), "DeliveryP", DeliveryPrecision, "Wt", VolumeWeight) // Creating a table with ID, weeknumber, Delivery precision and weight

 

RETURN SUMX(VALUES('Data ‘[ID]), CALCULATE(SUMX(DeliveryprecisionTable, [Wt] * [DeliveryP]))) // Sum to calculate the weighted average

 

 

1 ACCEPTED SOLUTION
miTutorials
Super User
Super User

Try the below measure and let me know if it works!

 

WeightedAverage_Delivery =
VAR _TotalVolume = CALCULATE(SUM('Data'[Volume]), ALL('Data'[ID])) 

VAR DeliveryprecisionTable =
    ADDCOLUMNS(
        SUMMARIZE('Data', 'Data'[ID], Calendar[WeekNum]),
        "DeliveryP", CALCULATE(SUM('Data'[DeliveryPrec])),
        "Wt", DIVIDE(CALCULATE(SUM('Data'[Volume])), _TotalVolume)
    )

RETURN 
SUMX(DeliveryprecisionTable, [Wt] * [DeliveryP])

 

View solution in original post

1 REPLY 1
miTutorials
Super User
Super User

Try the below measure and let me know if it works!

 

WeightedAverage_Delivery =
VAR _TotalVolume = CALCULATE(SUM('Data'[Volume]), ALL('Data'[ID])) 

VAR DeliveryprecisionTable =
    ADDCOLUMNS(
        SUMMARIZE('Data', 'Data'[ID], Calendar[WeekNum]),
        "DeliveryP", CALCULATE(SUM('Data'[DeliveryPrec])),
        "Wt", DIVIDE(CALCULATE(SUM('Data'[Volume])), _TotalVolume)
    )

RETURN 
SUMX(DeliveryprecisionTable, [Wt] * [DeliveryP])

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.