Forum Discussion

Jess303's avatar
Jess303
Frequent Visitor
4 years ago
Solved

Creating a new column using distinct count based off of unique value of a different column

So I am new to the DAX world and this is giving me a headache. I have multiple rows of IDs and I need to count how many unique customers for each ID. Column three is what I would like to see in my ta...
  • edhans's avatar
    4 years ago

    This will do it without invoking CALCULATE, which can cause problems in a Calculated Column.

    Customer Count = 
    VAR varCurrentID = Records[ID]
    VAR varCustomerCount =
        COUNTROWS(
            DISTINCT(
                SELECTCOLUMNS(
                    FILTER(
                        Records,
                        Records[ID] = varCurrentID
                    ),
                    "@Customers", Records[Customer]
                )
            )
        )
    RETURN
        varCustomerCount