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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Christoffer12
New Member

weighted Average on specifc lines of table

Hi All,

 

I have a simple table of country, product, sales volume, cost, sales price and margin (CM).

I want to calculate a few averages and weighted averages on it. Please see in example below. I have included the Excel "fromulas" as reference of what i am doing here. Can you help me recreating this in Power BI?
thanks in advance. 

 ABCDEFGHIJK
1 Prod-TypeVOLCostPriceCM  Counrtyweighted Average CMReference Formula Excel:
2USABaseline0%         1,000         1,30023%  US27.0% =SUMPRODUCT(C3:C4;F3:F4)
3USAProduct X40%         1,500         2,10029%  BR 24.1% =C6*F6+C8*F8
4USAProduct Y60%         2,000         2,70026%     
5Brazil WestBaseline0%         1,000         1,20017%     
6Brazil WestProduct X66%         1,500         2,00025% CounrtyProductMargin UpsideReference Formula Excel:
7Brazil EastBaseline0%         1,000         1,20017% USProduct X5% =F3-F2
8Brazil EastProduct Y33%         2,000         2,60023% USProduct Y3% =F4-F2
9       BR Product X8% =F6-F5
10       BR Product Y6% =F8-F7
11           
12       Counrtyweighted Average Margin UpsideReference Formula Excel: 
13       US3.9% =J7*C3+J8*C4 
14       BR 7.6% =J9*C6+J10*C8 

 

2 ACCEPTED SOLUTIONS
Christoffer12
New Member

HI rbriga.
thanks for your quick reply.

 

to the first one:

thanks that works.

 

to the second one:

If i apply the formula i get these margin upsides per product which seems to be incorrect. I am not sure if i need to transform data in any way to make the formula work. Thanks for your help to solve it 🙂

Christoffer12_0-1647416686560.png

 

to the third one:

works if the second one is corrected.

thanks again! 🙂


 

View solution in original post

Of course! "Baseline" was eliminated by the row context. 

Let's change the measure:

 

Margin Upside=
AVERAGE( 'TABLE'[CM] ) - CALCULATE(
    AVERAGE( 'TABLE'[CM] ),
    ALLSELECTED( 'TABLE'[Prod-Type] ),
    KEEPFILTERS( 'TABLE'[Prod-Type] ="Baseline" )
)

 

-------------------------
Data analyst by day, hockey goalie by night.
Did I help? Then please hit that "kudos" or "accept as a solution" button!

View solution in original post

3 REPLIES 3
Christoffer12
New Member

HI rbriga.
thanks for your quick reply.

 

to the first one:

thanks that works.

 

to the second one:

If i apply the formula i get these margin upsides per product which seems to be incorrect. I am not sure if i need to transform data in any way to make the formula work. Thanks for your help to solve it 🙂

Christoffer12_0-1647416686560.png

 

to the third one:

works if the second one is corrected.

thanks again! 🙂


 

Of course! "Baseline" was eliminated by the row context. 

Let's change the measure:

 

Margin Upside=
AVERAGE( 'TABLE'[CM] ) - CALCULATE(
    AVERAGE( 'TABLE'[CM] ),
    ALLSELECTED( 'TABLE'[Prod-Type] ),
    KEEPFILTERS( 'TABLE'[Prod-Type] ="Baseline" )
)

 

-------------------------
Data analyst by day, hockey goalie by night.
Did I help? Then please hit that "kudos" or "accept as a solution" button!
rbriga
Impactful Individual
Impactful Individual

The first is relatively simple. 

SUMX('TABLE NAME',
'TABLE NAME'[VOL]*'TABLE NAME'[CM]
)

and put it in context.

 

As for the second, 

you can go with

AVERAGE('TABLE NAME'[CM])-
CALCULATE(
AVERAGE('TABLE NAME'[CM]),
KEEPFILTERS('TABLE NAME'[Prod-Type] = "Baseline")
)

 

And the third:

SUMX('TABLE NAME',
'TABLE NAME'[VOL]*[Margin Upside]
)

where [Margin Upside] is the measure we created in step 2.

-------------------------
Data analyst by day, hockey goalie by night.
Did I help? Then please hit that "kudos" or "accept as a solution" button!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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