Forum Discussion

cliang's avatar
cliang
Frequent Visitor
3 years ago
Solved

Card doesn't change when slicing

Hello,

 

I have a few cards that are using DAX formulas to filter values but when I slice the data using different slicers, sometimes it changes and sometimes it doesn't. I've tried two different measures.

 

Here is the first:

 

Count of ID_KEY for Active student =
CALCULATE(
    DISTINCTCOUNT('Students_SM1'[ID_KEY]),
    'Students_SM1'[STUDENT_STATUS] IN { "Active student" }
)
 
Here is the second:
 
Count Active = CALCULATE(DISTINCTCOUNT(Students_SM1[ID_KEY]), Students_SM1[STUDENT_STATUS] = "Active student")
 
I'm slicing the STUDENT_STATUS attribute but it doesn't change the card. Any help would be great!
  • cliang 

    When you use Students_SM1[STUDENT_STATUS] = "Active student" in a calcualte that overrides any filter you apply to the Students_SM1[STUDENT_STATUS] column so that is why your slicer is not working.  If you want to count only the actives and not show anything if you turn off actives you need to include a KEEPFILTERS like this:

    Count Active =
    CALCULATE (
        DISTINCTCOUNT ( Students_SM1[ID_KEY] ),
        KEEPFILTERS ( Students_SM1[STUDENT_STATUS] = "Active Student" )
    )

3 Replies

  • cliang 

    When you use Students_SM1[STUDENT_STATUS] = "Active student" in a calcualte that overrides any filter you apply to the Students_SM1[STUDENT_STATUS] column so that is why your slicer is not working.  If you want to count only the actives and not show anything if you turn off actives you need to include a KEEPFILTERS like this:

    Count Active =
    CALCULATE (
        DISTINCTCOUNT ( Students_SM1[ID_KEY] ),
        KEEPFILTERS ( Students_SM1[STUDENT_STATUS] = "Active Student" )
    )
    • cliang's avatar
      cliang
      Frequent Visitor

      This worked! Thank you so much!

  • v-zhangti's avatar
    v-zhangti
    Icon for Community Support rankCommunity Support

    Hi, cliang 

     

    This is already a fixed count and does not change as the slicer changes.

    Count Active = CALCULATE(DISTINCTCOUNT(Students_SM1[ID_KEY]), Students_SM1[STUDENT_STATUS] = "Active student")

    Maybe you can try the following.
    Sample data:

    Count = 
    CALCULATE (
        DISTINCTCOUNT ( Students_SM1[ID_KEY] ),
        FILTER (
            ALL ( Students_SM1 ),
            [STUDENT_STATUS] = SELECTEDVALUE ( Students_SM1[STUDENT_STATUS] )
        )
    )

    Is this the result you expect?

     

    Best Regards,

    Community Support Team _Charlotte

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.