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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

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
Anonymous
Not applicable

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
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.