Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

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: cluster color value1 weights A blu 6,8 44 ...
  • v-yanjiang-msft's avatar
    4 years ago

    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.

    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.