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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
katbro20
Frequent Visitor

Weighted Average where weights are dynamic based on slicer

Hello,

 

I'm quite new to power BI and so hopefully I've posted this in the correct place. I'm trying to get the weighted average of a quarterly development % list weighted by sales premium, and I want the weights to be dynamic based based on what is selected in the slicer.

 

My sales data looks like this (this is not complete), and so there is a region, country/state, and product type associated with every sale premium.

katbro20_2-1729673736247.png

 

There are then two seperate tables which contain quarterly development list (again not complete) for every product type,

katbro20_3-1729673823976.png

and for every country/state.

katbro20_5-1729673869303.png

 

What I would like is to get a weighted average of the development pattern based on the sales premium (at the moment then development patterns are just showing simple average). The bit that I'm really struggling with is that I would like the ability to select multiple values from the slicers (eg select france and germany, and then have the weighted average of the  country/state development patterns just based on the premiums from those two countries).

 

I would then do this seperately for the other product type development pattern table based on the product type slicer (again with the ability to base the weights % on multiple selected values)

 

The last part would be to show the weighted average of both types of development patterns (the country/state and the product type) on the same graph, but I think if I have my relationships correct, that should be easy.

 

katbro20_6-1729673974330.png

This is a simplified version of what I'm trying to do, and so if explanations are needed then I will definately put some more color around the problem, just send post asking what I am missing!

 

Thank you very much!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @katbro20 ,

vzhouwenmsft_0-1729846185743.png

 

Best Regards,
Wenbin Zhou

View solution in original post

5 REPLIES 5
katbro20
Frequent Visitor

This is perfect, thank you very much

katbro20
Frequent Visitor

Posting data as tables for ease instead of pictures

SalesIDRegionCountry/StateProduct TypeSalesPremium
1USNew YorkA200
2USLAA300
3USNew YorkA400
4USLAB500
5USLAB600
6USLAB700
7USLAB800
8USBostonB900
9USBostonB1000
10USNew YorkD1100
11USNew YorkD1200
12USBostonD1300
13EuropeUKB1400
14EuropeUKB1500
15EuropeUKB1600
16EuropeFranceB1700
17EuropeFranceC1800
18EuropeFranceC1900
19EuropeFranceC2000
20EuropeGermanyC2100
21EuropeGermanyD2200
22EuropeGermanyD2300
23EuropeUKD2400
24EuropeUKD2500
25EuropeSpainA2600
26EuropeSpainA2700
27EuropeSpainA2800
28EuropeSpainB2900
29EuropeSpainB3000
30EuropeFranceB3100
31EuropeFranceB3200
32EuropeGermanyC3300
33EuropeGermanyC3400
34EuropeGermanyC3500
35EuropeGermanyC3600
36EuropeGermanyD3700
37EuropeUKD3800
38EuropeUKD3900
39EuropeUkD4000

 

 

Country/State Development Table

Country/StateQuarterDevelopment
New York10.05
New York20.1
New York30.15
New York40.2
New York50.25
New York60.3
New York70.35
New York80.4
New York90.45
New York100.5
Boston10.02
Boston20.045
Boston30.07
Boston40.095
Boston50.12
Boston60.145
Boston70.17
Boston80.195
Boston90.22
Boston100.245
LA10.1
LA20.2
LA30.3
LA40.4
LA50.5
LA60.6
LA70.7
LA80.8
LA90.9
LA101
France10.07
France20.14
France30.21
France40.28
France50.35
France60.42
France70.49
France80.56
France90.63
France100.7
UK10.05
UK20.1
UK30.15
UK40.2
UK50.25
UK60.3
UK70.35
UK80.4
UK90.45
UK100.5
Germany10.07
Germany20.14
Germany30.21
Germany40.28
Germany50.35
Germany60.42
Germany70.49
Germany80.56
Germany90.63
Germany100.7
Spain10.02
Spain20.045
Spain30.07
Spain40.095
Spain50.12
Spain60.145
Spain70.17
Spain80.195
Spain90.22
Spain100.245

 

Product Type Development Table

Product TypeQuarterDevelopment
A10.05
A20.1
A30.15
A40.2
A50.25
A60.3
A70.35
A80.4
A90.45
A100.5
B10.02
B20.045
B30.07
B40.095
B50.12
B60.145
B70.17
B80.195
B90.22
B100.245
C10.1
C20.2
C30.3
C40.4
C50.5
C60.6
C70.7
C80.8
C90.9
C101
D10.07
D20.14
D30.21
D40.28
D50.35
D60.42
D70.49
D80.56
D90.63
D100.7
Anonymous
Not applicable

Hi @katbro20 ,

How is the weighted average calculated?' Is 'Development' your weight column?
Like this?

vzhouwenmsft_0-1729763572327.png

If that is the case, this is the result I obtained

Product = 
VAR _quarter = SELECTEDVALUE('Quarter'[Value])
VAR _table = ADDCOLUMNS(SUMMARIZE('SalesData',[Product Type],"Sum",SUM(SalesData[SalesPremium])),"result",VAR _type = [Product Type] RETURN MAXX(FILTER('Product Type Development Table',[Product Type] = _type && [Quarter] = _quarter),[Development]) * [Sum])
VAR _a = SUMX(_table,[result])
VAR _b = CALCULATE(SUM('Product Type Development Table'[Development]),USERELATIONSHIP('Quarter'[Value],'Product Type Development Table'[Quarter]))
RETURN DIVIDE(_a,_b)

vzhouwenmsft_1-1729763612494.png

For quarter1 :
1928.57 = (900 * 0.05) + (4500 * 0.02) / (0.05 + 0.02)

 

If I have misunderstood, please let me know the steps of the calculation and the expected results

 

Best Regards,
Wenbin Zhou

Hi @Anonymous ,

 

No the developments are the things that I want weighted. Ie I would like a total development column by quarter, weighted by the premium (in the sales data) for each product type. (and for each country/state seperately if selected)

 

So very simply, if, for example, the slicer were to select product type A and B, I would like the weight for A in the Product Type Development Table to be the total premium for A (in the selected region) divided by the total premium for both product type A and B (in the selected region). So for example, if the US was selected:

 

katbro20_5-1729769090565.png

 

These weights would then be applied to every value in the development column for product type A and B respectively.

katbro20_2-1729768846852.png

The final result would then be the sum of the weighted development column for each quarter.

katbro20_4-1729769005222.png

Hopefully this is clearer, but let me know if not, thanks

Anonymous
Not applicable

Hi @katbro20 ,

vzhouwenmsft_0-1729846185743.png

 

Best Regards,
Wenbin Zhou

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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