Forum Discussion

carolinastalo's avatar
carolinastalo
Frequent Visitor
5 years ago
Solved

Problems with Context in Measures

Hello all I have this data structure: Employee          Total Cost   Department   John    $      1.000   A   Phil    $      2.000   A   Mary    $          800   B   ...
  • v-alq-msft's avatar
    5 years ago

    Hi, carolinastalo 

     

    Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

    Table:

     

    You may create measures as below.

    TC = SUM('Table'[Total Cost])
    SDC = 
    COALESCE(
        CALCULATE(
            SUM('Table'[Total Cost]),
            FILTER(
                'Table',
                'Table'[Department] in {"B","D"}
            )
        ),0
    )
    N-SDC = 
    COALESCE(
        CALCULATE(
            SUM('Table'[Total Cost]),
            FILTER(
                'Table',
                'Table'[Department] in {"A","C"}
            )
        ),0
    )
    Ratio = 
    DIVIDE(
        COALESCE(
            CALCULATE(
                SUM('Table'[Total Cost]),
                FILTER(
                    ALL('Table'),
                    'Table'[Department] in {"B","D"}
                )
            ),0
        ),
        COALESCE(
            CALCULATE(
                SUM('Table'[Total Cost]),
                FILTER(
                    ALL('Table'),
                    'Table'[Department] in {"A","C"}
                )
            ),0
        )
    )
    Cost With Ratio = [N-SDC]*(1+[Ratio])

     

    Result:

     

    Best Regards

    Allan

     

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