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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Calculation with different slice from the same table

Hi everyone, 

 

I am new to PowerBI and I am doing a project for my master. My issue is the following:

I have a table like the following:

clustercolorvalue1weights
Ablu6,844
Agreen7,810
Dblu7,922
Bgreen8,234
Cgreen8,423
Cblu6,822
Bblu8,423
Agreen7,811

 

The idea is to select one of the 4 clusters (i.e. A) as a filter and have a measure that computes the weighted average of value1 with the weights of the rest of the clusters (B C D).

 

I've tried several things but I am not even sure if something like this is possible. 

 

The formula that I want to apply is: 

SUM(table[value1 (filtered for cluster A)] * table[weights (notA)]) / SUM[weights(notA)]

Thank you in advance 🙂 

edit: wrong first term in sum

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your descriptin, in my understanding, if A is selected in the filter, your expected result is (6.8*44+7.8*10+7.8*11) / (22+34+23+22+23). Here is my solution.

Create a measure.

Measure =
VAR _select =
    SUMX (
        FILTER ( ALL ( 'myTable' ), 'myTable'[cluster] IN VALUES ( myTable[cluster] ) ),
        'myTable'[value1] * 'myTable'[weights]
    )
VAR _unselect =
    SUMX (
        FILTER (
            ALL ( 'myTable' ),
            NOT ( 'myTable'[cluster] IN VALUES ( myTable[cluster] ) )
        ),
        'myTable'[weights]
    )
RETURN
    DIVIDE ( _select, _unselect )

Get the result.

vkalyjmsft_1-1655284372525.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your descriptin, in my understanding, if A is selected in the filter, your expected result is (6.8*44+7.8*10+7.8*11) / (22+34+23+22+23). Here is my solution.

Create a measure.

Measure =
VAR _select =
    SUMX (
        FILTER ( ALL ( 'myTable' ), 'myTable'[cluster] IN VALUES ( myTable[cluster] ) ),
        'myTable'[value1] * 'myTable'[weights]
    )
VAR _unselect =
    SUMX (
        FILTER (
            ALL ( 'myTable' ),
            NOT ( 'myTable'[cluster] IN VALUES ( myTable[cluster] ) )
        ),
        'myTable'[weights]
    )
RETURN
    DIVIDE ( _select, _unselect )

Get the result.

vkalyjmsft_1-1655284372525.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

selimovd
Super User
Super User

Hey @Anonymous ,

 

it would be easier with a real file or tables. But the following approach should do it:

Weighted Average =
VAR vSelectedClusters = VALUES ( myTable[cluster] )
VAR vWeightNotCluster =
    CALCULATE (
        SUM ( myTable[weights] ),
        ALL ( myTable ),
        NOT ( myTable[weights] ) IN vSelectedClusters
    )
RETURN
    ( SUM ( myTable[weights] ) * vWeightNotCluster ) / vWeightNotCluster

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍

Best regards
Denis

Blog: WhatTheFact.bi
Follow me: twitter.com/DenSelimovic
 

Anonymous
Not applicable

Hi, thanks for your reply! 

 

I tried this answer and it says there's an error:

Error Message:
MdxScript(Model) (47, 45) Calculation error in measure 'overall_pivot_table'[Weighted Average]:
The function 'CONTAINSROW' does not support the comparison between values of type Text and type Integer.
Try to use the functions VALUE or FORMAT to convert one of the values.

I translated from italian.

 

I edit my post with the right formula. 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.