Forum Discussion

elouizi's avatar
elouizi
Helper II
5 years ago
Solved

only count selected values show selected

Hi There,

 

I am new to DAX. 
I want to write a messure that counts the number of unique products that a user selects in a certain column.


I wrote the following query:

only count number of selected values = CALCULATE(DISTINCTCOUNT('Sales Sheet'[Product]), ALLSELECTED('Sales Sheet'[Product])



when use this messure in a card visual I get 5. Which is the total number of products. But no selection has been made.
I would have expected blank or 0, since no selection has been made.

I would appriciate some help.
Thank you.

  • elouizi's avatar
    elouizi
    5 years ago

    Thank you for you for you help.
    I used the following. and now it works:

    only count number of selected values = CALCULATE(
    (ISFILTERED('Sales Sheet'[Product]) * DISTINCTCOUNT('Sales Sheet'[Product])),
                                                                                                 ALLSELECTED('Sales Sheet'[Product]))



4 Replies

  • elouizi 

    You can just use :

    Measure = CALCULATE(DISTINCTCOUNT('Sales Sheet'[Product]))

     

    • elouizi's avatar
      elouizi
      Helper II

      Unfortunatelly. That does not give me the right results.
      The table is being used as a filter. The filter in the table should be ignored and only the external filter should be activated.

      when no selection has been made. I see the folowing in a table:

      product                    messure              desired result

      A                                1                         0 when nothing has been selected by the user. 1 when a user selects somehting (same for the others)

      B                                1                         0

      C                                1                         0

      D                                1                         0
      total                           4                         0

       

       

  • CNENFRNL's avatar
    CNENFRNL
    Community Champion
    number of selected values = ISFILTERED( 'Sales Sheet'[Product] ) * DISTINCTCOUNT( 'Sales Sheet'[Product] )
    • elouizi's avatar
      elouizi
      Helper II

      Thank you for you for you help.
      I used the following. and now it works:

      only count number of selected values = CALCULATE(
      (ISFILTERED('Sales Sheet'[Product]) * DISTINCTCOUNT('Sales Sheet'[Product])),
                                                                                                   ALLSELECTED('Sales Sheet'[Product]))