## Desktop

Highlighted
Regular Visitor
Posts: 26
Registered: ‎12-11-2017

# formula to group customers based on items they have

Is there a formula to assign a customer to a group based on certian items they have? If the customer has one of the bold letter items in the group below they will automatically be assigned to that group even if they have other items that are not in bold letters

Data set 1

Group 1 - car, house, bike, motorcycle

Group 2 - car, boat

Group 3 - house, motorcycle

Data set 2

David - house, motorcycle, bike

John - car, boat

Mike - house, car

Return value

David = Group 1

John = Group 2

Mike = Group 3

Accepted Solutions
New Contributor
Posts: 444
Registered: ‎02-15-2018

## Re: formula to group customers based on items they have

Is this a Measure or Calc Column?

If its a column then this should work - not sure how your data is organized so I took a guess.  after I wrote the below I  rememberd you can probalby use the IN {"house","car"} vs the || operator but I think you will get the approach.  If you need more help can you can share your model and table layout even if its just the field names and header rows and give a better idea of the resutls your after.

```Group Column = SWITCH(TRUE(),
CALCULATE(COUNTROWS(VALUES(policies[PolicyType]), FILTER(policies,policy[type]="car"||policy[type]="house"||policy[type]="bike"||policy[type]="motorcycle")=4,"1",
CALCULATE(COUNTROWS(VALUES(policies[PolicyType]), FILTER(policies,policy[type]="car"||policy[type]="boat"||=2,"2"
….

```

All Replies
Super User
Posts: 1,974
Registered: ‎07-22-2015

## Re: formula to group customers based on items they have

What happens if person has both bold items belongs to diffrent groups, what group he will be assigned in that case?

Proud to be a Datanaut!

www.perytus.com
(MVP Data Platform)

Regular Visitor
Posts: 26
Registered: ‎12-11-2017

## Re: formula to group customers based on items they have

They would be assigned to the highest group.

The Ranking would be Group 1 > Group 2 > Group 3

New Contributor
Posts: 444
Registered: ‎02-15-2018

## Re: formula to group customers based on items they have

Is this a Measure or Calc Column?

If its a column then this should work - not sure how your data is organized so I took a guess.  after I wrote the below I  rememberd you can probalby use the IN {"house","car"} vs the || operator but I think you will get the approach.  If you need more help can you can share your model and table layout even if its just the field names and header rows and give a better idea of the resutls your after.

```Group Column = SWITCH(TRUE(),
CALCULATE(COUNTROWS(VALUES(policies[PolicyType]), FILTER(policies,policy[type]="car"||policy[type]="house"||policy[type]="bike"||policy[type]="motorcycle")=4,"1",
CALCULATE(COUNTROWS(VALUES(policies[PolicyType]), FILTER(policies,policy[type]="car"||policy[type]="boat"||=2,"2"
….

```

Regular Visitor
Posts: 26
Registered: ‎12-11-2017

Thanks all!