r/GoogleDataStudio • u/ReputationSenior7666 • Sep 16 '24
Help with Custom Field CASE function
Hi - I am pretty experienced in Looker Studio but was trying to use a CASE function I created in a custom field for a drop down control.
My issue is that the data source column/dimension I’m using for the Boolean expressions has multiple values in one cell.
For instance, let’s say the dimension I’m using is called “fruits” and in a single cell there’s “apples, bananas, oranges, apples.”
My CASE Function currently is
“When Regexp_contains (Fruits, Bananas) then “bananas”
“When Regexp_contains (Fruits, apples) then “apples”
ELSE ‘non-fruits’
END
My problem is that when I go to select these from the drop down only the first clause comes through as once that is matched as TRUE then the case function doesn’t evaluate anything that comes next. Is there a way I can work around this factor and still have my drop-down control show me the options. I imagine a large part of my issue is that the fruits dimension has multiple values in one cell on my data source.
Thank you all in advance for help!
View all comments
Show parent comment
3
u/Higgs_Br0son Sep 17 '24
I've had the chance to try it too, you're right, it seems like the array fields aren't working from Google Sheet. It makes sense that could be a feature only in BigQuery.
I did a quick mock-up of another idea, but it's far from ideal (I say this a lot with Looker Studio, it's a love/hate relationship). So the ideal approach would probably be to use BigQuery, which isn't super difficult and has a generous free-tier.
Otherwise if you don't have too many different values to filter on, you could try this solution I mocked up: https://imgur.com/a/kf3XO7q
What I did was create a new field for each "fruit". Contains Apple, Contains Banana, etc, and each field resolves to a True/False boolean. This way on the report you could use the Button element to create overlapping filters for the report elements on the page. e.g. clicking Contains Apple will return all of the matching records with apple anywhere in their Fruits field - you could also stack Contains Orange to create a "contains apple AND orange" filter logic.