Forum Discussion

meiwah's avatar
meiwah
Resolver I
3 years ago
Solved

How reference row context in addcolumn

I've a table as below which contains the CaseID of a case, the division of a case and the predicted division of a case. This predicted value is computed by calling a ML model.    CaseID  Divisi...
  • meiwah's avatar
    3 years ago

    Thank you for all help! I've managed to find the solution.

     

    ADDCOLUMNS(
       values(Table[Division]),
       "No Cases", CALCULATE(countrows(Table)),
       "No Predictions", CALCULATE(COUNTROWS(Table), Table[Division Prediction]=earlier([Division]), All(Table[Division]))
    )

     

    I have used the first column in AddColumns as the table I intend to loop through, which is Division.

     

    Then use Calculate to do a context transition, bringing Table[Division] the row context into the filter context. Hence, "No Cases" will have the correct figure.

     

    Then use Earlier to reference the filter context from outside of Calculate, to use it on Table[Division Prediction]. Remove the filter on Table[Division]