Forum Discussion
Measure: count if value does not appear in another column
- 7 years ago
Hi Anonymous
Unfortunately, I don't know what is the structure of your dataset, but it worked ok when applied to the sample you have provided.
All() - Removes all filters from a current filter context this allows the measure to count occurrences of 5 that are in different rows.
VAR x = VALUES( 'Table'[Column1] ) -- this part selects distinct value for column1 in each give row and all values for total RETURN CALCULATE( COUNTROWS( 'Table' ), -- count rows in a table in a filter context created by CALCULATE ALL(), - removes all filters TREATAS( x, 'Table'[Column2] ) -- filters table where column2 = column1 ) + 0Best Regards,
Mariusz
If this post helps, then please consider Accepting it as the solution.
Please feel free to connect with me.
Hi Anonymous
You can try the below.
Measure =
VAR x = VALUES( 'Table'[Column1] )
RETURN
CALCULATE(
COUNTROWS( 'Table' ),
ALL(),
TREATAS( x, 'Table'[Column2] )
) + 0
Mariusz
If this post helps, then please consider Accepting it as the solution.
Please feel free to connect with me.
Thanx!
It works well on the row level, however the measure total does not give the sum on the row values. What is the logic for the measure total calculation?
Secondly, could you please tell me, why the ALL() is needed in there (why without it it does nnot work on the row level?
Thanks in advance!
- Mariusz7 years ago
Community Champion
Hi Anonymous
Unfortunately, I don't know what is the structure of your dataset, but it worked ok when applied to the sample you have provided.
All() - Removes all filters from a current filter context this allows the measure to count occurrences of 5 that are in different rows.
VAR x = VALUES( 'Table'[Column1] ) -- this part selects distinct value for column1 in each give row and all values for total RETURN CALCULATE( COUNTROWS( 'Table' ), -- count rows in a table in a filter context created by CALCULATE ALL(), - removes all filters TREATAS( x, 'Table'[Column2] ) -- filters table where column2 = column1 ) + 0Best Regards,
Mariusz
If this post helps, then please consider Accepting it as the solution.
Please feel free to connect with me.