Forum Discussion
c0ld
4 years agoRegular Visitor
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...
- Anonymous4 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
Anonymous
4 years agoNot applicable
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
c0ld
4 years agoRegular Visitor
Hi Xiaoxin,
This is exactly what i needed !
Thank you for taking the time to help out 🙂