Filter with Contains rather than Equals

The use case is that I have a form where a user will choose red, blue, or green in the โ€œCOLOR SELECTION FIELDโ€.

I have a field (as shown below) that will return all columns from another table when that selection above is found in the โ€œCOLORSโ€ column for that other table.

FILTER(โ€œTABLEโ€, ([COLOR SELECTION] = [COLORS] ))
What I want is FILTER ROWS WHERE COLOR SELECTION IS CONTAINED WITHIN COLORS and also to choose the columns if possible.

The COLORS field is not an exact match to COLOR SELECTIONโ€ฆmore like tags where it can have yellow, green, blue (comma separated). I want all COLORS column values where COLOR SELECTION = โ€œBlueโ€ for example, whether exact match or if โ€œBlueโ€ is simply found in the COLORS value ( yellow, green, blue for example).

Solved Solved
0 11 810
1 ACCEPTED SOLUTION

Aurelien
Google Developer Expert
Google Developer Expert

Hi @Sam87

What about:

FILTER(โ€œTABLEโ€,
  CONTAINS([COLORS], [_THISROW].[COLOR SELECTION])
)

For reference:

View solution in original post

11 REPLIES 11

Aurelien
Google Developer Expert
Google Developer Expert

Hi @Sam87

What about:

FILTER(โ€œTABLEโ€,
  CONTAINS([COLORS], [_THISROW].[COLOR SELECTION])
)

For reference:

Thanks,

I used this and it works great!

FILTER(โ€œTABLEโ€,
CONTAINS([COLORS], [_THISROW].[COLOR SELECTION])
)

I decided to just return one column from the lookup table based on the contains.

I used SELECT(COLORSTABLE[RETURN COLUMN], CONTAINS([COLORS], [_THISROW].[COLOR SELECTION])
)

For some reason the whole table is being returned (with the proper contains result) rather than just the return column. Any thoughts?

You may want to share a screenshot in order to help us better understand what you describe, as well as a screenshot of your table structure.

I neglected about the IN(), donโ€™t know whyโ€ฆ

@Sam87 Did you see @Steveโ€™s suggestion ?

Edit : I remember : because in my mind, IN() is about looking for an item in a list.
Here, @Sam87 is looking for an item in โ€œsomething I understood as being of type textโ€.
@Steve , your opinion ?

If the data being searched is a simple textual value, CONTAINS() is the correct choice.

I am good with this, works. It works great now with containsโ€ฆbut my alternate formula to just pull one column from the table on the match isnโ€™t working. It returns all columns:

SELECT(COLORSTABLE[RETURN COLUMN], CONTAINS([COLORS], [_THISROW].[COLOR SELECTION])
)

The good row but all the columns ? ==> that makes me think:

  • your column [RETURN COLUMN ] is of type Ref
  • this is the key_column of your table that it refers to

Can you provide screenshot in order to confirm/deny this ?


That is my return column. It is text.

This returns all columns rather than just the โ€˜Reason for PR Failureโ€™ column

SELECT(SystemFix[Reason for Failure], CONTAINS([Tags],[Field of concern]))
Note: This expression could impact performance.

The list of values of column โ€˜Reason for PR Failureโ€™
โ€ฆfrom rows of table โ€˜SystemFixโ€™
โ€ฆwhere this condition is true: ((The value of column โ€˜Tagsโ€™) contains the text value (The value of column โ€˜Field of concernโ€™))

I was interested in a screenshot of the output too, sorry for not having been clear.

I think you donโ€™t display every necessary information, as the SELECT expression in your last post is not visible in the screenshot provided.
Also, a SELECT returns a list. a Text type is not appropriate, you might want to change it to a List type.

Top Labels in this Space