Forum Discussion

tod's avatar
tod
Frequent Visitor
5 years ago
Solved

Calculation between rows with conditions

Hi,

I'm trying to create a custom column showing % from data between rows. Best way to show what I'm trying to do is the data set here:

Column AColumn BColumn CCustom Column D
1A202%
1B1000100%
1C758%
1D25025%
2A302%
2B1500100%
2C1007%
2D503%
3A101%
3B800100%
3C203%
3D203%

 

The % calculation is always against B, but B repeats in Column B because Column A has several sets like different years. DAX or M formula is fine, but the data set is very large so perfomance is a consideration. Appreciate any and all help!

  • Hi tod  ,  

     

    You could create a measure by the following formula: 

    Custom Column D =
    MAX ( [Column C] )
        / CALCULATE (
            MAX ( 'Table'[Column C] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Column A] = MAX ( 'Table'[Column A] ) ),
            'Table'[Column B] = "B"
        )
    

    The final output is shown below:  

    Best Regards,
    Community Support Team_ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.   

3 Replies

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Community Support

    Hi tod  ,  

     

    You could create a measure by the following formula: 

    Custom Column D =
    MAX ( [Column C] )
        / CALCULATE (
            MAX ( 'Table'[Column C] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Column A] = MAX ( 'Table'[Column A] ) ),
            'Table'[Column B] = "B"
        )
    

    The final output is shown below:  

    Best Regards,
    Community Support Team_ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.   

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    Please try this column expression.  Rename the Table from PctOfB to your actual table name throughout.

     

    PctOfBColumn =
    VAR thisvalue = PctOfB[Column C]
    VAR thisAvalue = PctOfB[Column A]
    VAR thisAvalueB =
        AVERAGEX (
            FILTER ( PctOfB, PctOfB[Column A] = thisAvalue && PctOfB[Column B] = "B" ),
            PctOfB[Column C]
        )
    RETURN
        DIVIDE ( thisvaluethisAvalueB )

     

    Pat

     

  • tod's avatar
    tod
    Frequent Visitor

    Thanks Pat. Using your formula, Columns A and C are summing as shown. They should remain in their original format. None of the columns are "summarized"; they are "Don't summarize".

    This is how I interpreted your formula:

     
    Custom Custom =
    VAR thisvalue = 'Table'[Column C]
    VAR thisAvalue = 'Table'[Column A]
    VAR thisAvalueB =
    AVERAGEX (
    FILTER ( 'Table', 'Table'[Column A] = thisAvalue && 'Table'[Column B] = "B" ),
    'Table'[Column C]
    )
    RETURN
    DIVIDE ( thisvalue, thisAvalueB )
     
    Did I do this right?