Forum Discussion

c0ld's avatar
c0ld
Regular Visitor
4 years ago
Solved

Sum previous rows in a new column

Hello PowerBI gurus,   I am trying to visualise model performance metrics in line graphs so I have created 4 columns which capture the TP, FP, TN and FN predictions that the model has made.   Bas...
  • Anonymous's avatar
    Anonymous
    4 years ago

    HI c0ld,

    Account to your description, it sounds like a cumulative calculation between two fields. Do any Index fields exist in your tables?  If that is the case, you can refer to the following DAX formula to get results.

    Measure:

     

    formula =
    VAR currIndex =
        MAX ( Table[Index] )
    VAR rollTP =
        CALCULATE (
            SUM ( Table[TP] ),
            FILTER ( ALLSELECTED ( Table ), [Index] <= currIndex )
        )
    VAR rollFN =
        CALCULATE (
            SUM ( Table[FN] ),
            FILTER ( ALLSELECTED ( Table ), [Index] <= currIndex )
        )
    RETURN
        DIVIDE ( rollTP, rollTP + rollFN )

     

    Calculated column:

     

    formula =
    VAR rollTP =
        CALCULATE (
            SUM ( Table[TP] ),
            FILTER ( Table, [Index] <= EARLIER ( Table[Index] ) )
        )
    VAR rollFN =
        CALCULATE (
            SUM ( Table[FN] ),
            FILTER ( Table, [Index] <= EARLIER ( Table[Index] ) )
        )
    RETURN
        DIVIDE ( rollTP, rollTP + rollFN )

     

    Regards,

    Xiaoxin Sheng