Forum Discussion

MaleneL's avatar
MaleneL
Resolver I
2 years ago
Solved

finding customer with two different status

Hoping for help  I have at table where at customer the same month can have two status' and i want two make at dax finding the customer wich have or also have a Leavers status:   Anyone that ...
  • AmiraBedh's avatar
    2 years ago

    You need to create a DAX measure or calculated column that will count the number of distinct statuses for each customer in a given month. If the count is greater than 1 and one of the statuses is 'leavers', then you can mark that customer as "Also Leavers".

     

    Also Leavers Column =
    VAR CurrentCustomer = [Customer ID]
    VAR CurrentMonth = MONTH([date])
    VAR CurrentYear = YEAR([date])
    VAR LeaversCount =
    CALCULATE(
    COUNTROWS(
    FILTER(
    'TableName',
    'TableName'[Customer ID] = CurrentCustomer &&
    MONTH('TableName'[date]) = CurrentMonth &&
    YEAR('TableName'[date]) = CurrentYear &&
    'TableName'[status] = "leavers"
    )
    )
    )
    VAR TotalStatus =
    CALCULATE(
    COUNTROWS(
    FILTER(
    'TableName',
    'TableName'[Customer ID] = CurrentCustomer &&
    MONTH('TableName'[date]) = CurrentMonth &&
    YEAR('TableName'[date]) = CurrentYear
    )
    )
    )
    RETURN
    IF(LeaversCount > 0 && TotalStatus > 1, "Also Leavers", BLANK())