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! Request now

Reply
Capoccetta
Regular Visitor

Problem with weighted average formula

Dear all,

I’m new in power BI and I have a problem for calculating a weighted average based on a total of a column.

In attach a simplified example for my PBIX.

As you can see I have two table, a master table and a summarize table, with few fields calculated from master table. On summarized table I have a drivermonth field that represent the key of the tables, a field that represent sum of sales for driver, and distinct count number of deliveries for driver.

On the report I have a page filter where I can filtered the name of driver.

I want to calculate a weighted average, I’m trying with different formulas but all give me a wrong result because all calculation are carried out on the total number of the delivery, 21 and not only on the delivery filtered…

The formula used for SalesxDeliveries/TotalDeliveries is

SalesxDeliveries/TotalDeliveries = (Compatti[Delivery]*Compatti[Sales])/(SUM(Compatti[Delivery]))

I’m trying also with filter but without results

This is the total records

Img1.png

This is filtered records

Img2.png

In the last column the formula consider the total number of deliveries 21 instead of filtered dynamically 18

That is the result that I expect

Img3.png

 

Please give me a tips....

 

Thanks

1 ACCEPTED SOLUTION

with this formula works fine

 

SalesxDeliveries/TotalDeliveries =
DIVIDE (
    SUMX ( Compatti, Compatti[Delivery] * Compatti[Sales] ),
    CALCULATE ( SUM ( Compatti[Delivery] ), ALLSELECTED ( Compatti ) )
)

 

Thanks to all....

 

 

View solution in original post

12 REPLIES 12
Anonymous
Not applicable

@Capoccetta,

Create a measure using DAX below.

Measure = SUM(Compatti[Sales])*SUM(Compatti[Delivery])/CALCULATE( SUM(Compatti[Delivery]),ALLSELECTED(Compatti[Driver]))

1.JPG
Regards,
Lydia

This is my PBIX https://1drv.ms/u/s!AqfsJnD6F-2ggdhEmH0ydA3nfpuHLQ

It's the same formula that I'm checking

Measure1 = SUM(Compatti[Sales])*SUM(Compatti[Delivery])/CALCULATE(SUM(Compatti[Delivery]);ALLSELECTED(Compatti[DriverMonth]))

 

but this is my result.... It's no correct...

 

Img4.png

 

 

Anonymous
Not applicable

@Capoccetta,

You would need to create the following measures in the sheet1 table and create a new table visual as folllows.

SalesxDelivery = SUM(Compatti[Sales])*SUM(Compatti[Delivery])
AllDelivery = CALCULATE(SUM(Compatti[Delivery]),ALLSELECTED(Sheet1[Driver]),ALL(Sheet1[DriverMonth]))
ExpectedMeasure = [SalesxDelivery]/[AllDelivery]

1.JPG

Regards,
Lydia

@Anonymous

 

Tks Lydia for your attention...

Only a thing.... The meaure work correctly but the total of the column it's wrong.

 

Anonymous
Not applicable

Dear @Capoccetta,

 

Can you share again your pbix again, I'll make formular and check on it.

 

Regards,

ManNVSM

@Anonymous

This last pbix modified

 

https://1drv.ms/u/s!AqfsJnD6F-2ggdhFCiMqkwzPACHG-w

 

Thanks

Anonymous
Not applicable

Dear @Capoccetta,

 

I'm just realize that your Formular is not good.

SalesxDeliveries/TotalDeliveries = (Compatti[Delivery]*Compatti[Sales])/(SUM(Compatti[Delivery]))

With GrandTotal, it value will = Sales.

Example: (A*B)/A = B. Because A/A = 1.

So (1*B) =B. In this case, A = Delivery, B = Sale. Right?

 

You can see a picture below. So, you can give me more about your request, maybe we find another way to solve it.

 

image.png

 

 

Dear @Anonymous

It's all correct... I thought the same

The aim is to calculate for every item the weighted average and to have a correct total of the relatively column.

 

 

Anonymous
Not applicable

Dear @Capoccetta,

 

Yup.

 

Now Table can not let us choose what will for Grandtotal. Maybe sum from the detail or maybe from Formular (default). Hope it comming soon by Idea.

If you need a hand on the other issue, just tag my account in your topic 🙂

 

Btw, if you thing what reply is solution, please choose it to close this Topic.

 

Regards,

ManNVSM.

Dear @Anonymous

the solution is to have the Expected Measure Formula and the same results on a column formula, one or more columns.

One column with detail results and another column with a total of selected records which can I use as grandtotal...

 

I'm cheking it but now without results...

 

In your opinion based on your experience Is it possibile?

 

 

@Capoccetta

 

Hi, try this:

 

Modify:

 

AllDelivery =
CALCULATE (
    SUM ( Compatti[Delivery] ),
    ALLSELECTED ( Sheet1[Driver] ),
    ALLSELECTED ( Sheet1[DriverMonth] )
)

And create a new measure

 

ExpectedMeasure VV =
IF (
    HASONEVALUE ( Sheet1[Driver] ),
    [ExpectedMeasure],
    SUMX (
        SUMMARIZE (
            Sheet1,
            Sheet1[Driver],
            Sheet1[DriverMonth],
            "AA"; [SalesxDelivery] / [AllDelivery]
        ),
        [AA]
    )
)

You can Change the AA to another name and replace expected measure with the code.

 

Img1.png

 

Regards

 

Victor

Lima - Peru




Lima - Peru

with this formula works fine

 

SalesxDeliveries/TotalDeliveries =
DIVIDE (
    SUMX ( Compatti, Compatti[Delivery] * Compatti[Sales] ),
    CALCULATE ( SUM ( Compatti[Delivery] ), ALLSELECTED ( Compatti ) )
)

 

Thanks to all....

 

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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