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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
sunnycube
New Member

Weighted average of the only the products that appear in ALL selected columns

I have a mock dataset that contains sales data from 4 different companies (OWN COMPANY, competitor 1-3). I already created a few measures, including the weighted average price:

 

Weighted AVG Price = SUMX('Example Data', 'Example Data'[Price]*'Example Data'[Units]) / SUM('Example Data'[Units])

 

sunnycube_0-1747313326232.png

 

Now I want to be able to apply a filter to it. For example, if I select only 2 competitors, I want the weighted average of only those products that are present in both of the selected competitors. Right now, the weighted average stays the same, no matter which competitor I select. I already tried a bunch of different stuff but it always stays unchanged.... Can someone please help?

 

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You can try

Weighted Average =
VAR Companies =
    CALCULATETABLE (
        VALUES ( 'Example Data'[Competitor] ),
        ALLSELECTED ( 'Example Data'[Competitor] )
    )
VAR NumCompanies =
    COUNTROWS ( Companies )
VAR CompaniesAndProducts =
    GENERATE ( Companies, CALCULATETABLE ( VALUES ( 'Example Data'[Product ID] ) ) )
VAR ProductsAndNumCompanies =
    GROUPBY (
        CompaniesAndProducts,
        'Example Data'[Product ID],
        "@num", SUMX ( CURRENTGROUP (), 1 )
    )
VAR ProductsInAll =
    FILTER ( ProductsAndNumCompanies, [@num] = NumCompanies )
VAR Result =
    CALCULATE (
        SUMX ( 'Example Data', 'Example Data'[Price] * 'Example Data'[Units] )
            / SUM ( 'Example Data'[Units] ),
        KEEPFILTERS ( ProductsInAll )
    )
RETURN
    Result

View solution in original post

2 REPLIES 2
v-pagayam-msft
Community Support
Community Support

Hi @sunnycube ,
Thank you @johnt75 for the helpful response!

I tried to recreate it with the sample data.Please find the file and screenshot.

vpagayammsft_0-1747373788664.png

I hope this resolve your query.If my answer meets your requirement,give us kudos and consider accepting it as solution.

Regards,
Pallavi.

johnt75
Super User
Super User

You can try

Weighted Average =
VAR Companies =
    CALCULATETABLE (
        VALUES ( 'Example Data'[Competitor] ),
        ALLSELECTED ( 'Example Data'[Competitor] )
    )
VAR NumCompanies =
    COUNTROWS ( Companies )
VAR CompaniesAndProducts =
    GENERATE ( Companies, CALCULATETABLE ( VALUES ( 'Example Data'[Product ID] ) ) )
VAR ProductsAndNumCompanies =
    GROUPBY (
        CompaniesAndProducts,
        'Example Data'[Product ID],
        "@num", SUMX ( CURRENTGROUP (), 1 )
    )
VAR ProductsInAll =
    FILTER ( ProductsAndNumCompanies, [@num] = NumCompanies )
VAR Result =
    CALCULATE (
        SUMX ( 'Example Data', 'Example Data'[Price] * 'Example Data'[Units] )
            / SUM ( 'Example Data'[Units] ),
        KEEPFILTERS ( ProductsInAll )
    )
RETURN
    Result

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.