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
amitchandak
Super User
4 years agoc0ld , Try a measure like
Recall= DIVIDE(sum('Table'[TP_Stg_1]) , sumx('Table','Table'[TP_Stg_1] + 'Table'[FN_Stg_1]), 0)