1
votes

I have created two groups on a customer level (all with distinct customer IDs) based on some criterias. But I am having difficulties grouping these on a group level (group ID). The data structure is a follows: a customer has one customer ID and a group ID. The customer ID is distinct but the group ID is not; i.e. multiple customers (customer IDs) are part of a group and therefore have the same group ID.

My tableau code looks something like this:

IF [Sales] >= 200000 and [Category] = 'A' 
OR [CAC] <= 10000 and [Category] = 'A' 
THEN 'Good customer'
ELSE 'Bad customer'
END

The above code gives me the grouping on a customer level. However, I want to see the group level, i.e. if just one customer from a group is a 'Good customer' then the entire group should be classified as a 'Good customer'. This means that if just one customer from the group is classied as a 'Good customer' then all the [Sales] and [CAC] of the customers within the particular group should be summed up on a group level and displayed under 'Good customer' on a group level instead of on customer level.

1

1 Answers

1
votes

Try this:

Create a field [GoodCustomer] with this formula:

IF [Sales] >= 200000 AND [Category] = 'A' 
OR [CAC] <= 10000 AND [Category] = 'A' 
THEN 1
ELSE 0
END

This is your condition but assigns a numeric value to it (1 = good customer, 0 = bad customer)

Create a field [GoodGroup] with this formula:

{fixed [Group]: IIF(SUM([GoodCustomer]) > 0, True, False)}

For each group this checks if the sum of [GoodCustomer] is greater 0 (which means that at least one customer was good). If this is true it sets it to True (or use 'Good Group') if it is false, set it to False (or 'Bad Group')

This should give you what you described above.