Forum Discussion

BharatM's avatar
BharatM
New Member
8 years ago
Solved

DAX - counting based on two columns

Hi,

 

I am fairly new to DAX. I have been struggling all day to solve a particular problem and would be grateful if someone can help guide me. I have a list of customers and data looks like this (dummy example):

 

Customer IDChoice
101Desk
101Chair
101Chair
102Chair
102Chair
103Desk
104Desk
104Chair
105Chair
105Chair
105Desk
105Chair
106

Desk

 

Eash customer can have multiple entries. However I want to extract only the ID of those customer who have chosen "Chair" only and nothing else - in this example 102 and 106. I have scratched my head and tried different thing and have failed. 

 

Thank you.

 

Bharat

  • BharatM

     

    I would suggest creating either a calculated column or measure using this code:

    Chair only =
    IF (
        CALCULATE (
            SELECTEDVALUE ( Choices[Choice] ),
            ALLEXCEPT ( Choices, Choices[Customer ID] )
        )
            = "Chair",
        1
    )

    Then apply a visual level filter (or any sort of filter in the case of a calculated column) Chair only = 1

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Create a calculated column

     

    IsChair = IF(Table1[Choice] = "Chair", 1, 0)

     

    Then sum it in the display

    • BharatM's avatar
      BharatM
      New Member

      Will this not also count those customer IDs who have chair and desk or table? I want only those customers who have chair and nothing else as a selection.

      • OwenAuger's avatar
        OwenAuger
        Super User

        BharatM

         

        I would suggest creating either a calculated column or measure using this code:

        Chair only =
        IF (
            CALCULATE (
                SELECTEDVALUE ( Choices[Choice] ),
                ALLEXCEPT ( Choices, Choices[Customer ID] )
            )
                = "Chair",
            1
        )

        Then apply a visual level filter (or any sort of filter in the case of a calculated column) Chair only = 1