0
votes

I want to count the occurrences of values in a column. In my case the value I want to count is TRUE(). Lets say my table is called Table and has two columns:

boolean value
TRUE()  A
FALSE() B
TRUE()  A
TRUE()  B

All solutions I found so far are like this:

count_true = COUNTROWS(FILTER(Table, Table[boolean] = TRUE()))

The problem is that I still want the visual (card), that displays the measure, to consider the filters (coming from the slicers) to reduce the table. So if I have a slicer that is set to value = A, the card with the count_true measure should show 2 and not 3.

As far as I understand the FILTER function always overwrites the visuals filter context.

To further explain my intent: At an earlier point the TRUE/FALSE column had the values 1/0 and I could achieve my goal by just using the SUM function that does not specify a filter context and just acts within the visuals filter context.

2

2 Answers

0
votes

I do not know for sure if this will fix your problem but it is more efficient dax in my opinion:

count_true = CALCULATE(COUNTROWS(Table), Table[boolean])

If you still have the issue after changing your measure to use this format, you may have an underlying issue with the model. There is also the function KEEPFILTERS that may apply here but I think using KEEPFILTERS is overcomplicating your case.

0
votes

I think the DAX you gave should work as long as it's a measure, not a calculated column. (Calculated columns cannot read filter context from the report.)

When evaluating the measure,

count_true = COUNTROWS ( FILTER ( Table, Table[boolean] = TRUE() ) )

the first argument inside FILTER is not necessarily the full table but that table already filtered by the local filter context (including report/page/visual filters along with slicer selections and local context from e.g. rows/column a matrix visual).

So if you select Value = "A" via slicer, then the table in FILTER is already filtered to only include "A" values.