Forum Discussion
How reference row context in addcolumn
- 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]
I would create a dimension table for your divisions, simply DISTINCT('Table'[Division]), create an active relationship from this to the division column in your fact table and create an inactive relationship from it to your predicted division column. You could then create measures like
No Cases = COUNTROWS( 'Table' )
No Predicted Cases = CALCULATE( COUNTROWS('Table'), USERELATIONSHIP( 'Table'[Predicted Division], Division[Division]) )