-2

I am trying to group certain source/medium dimensions in Google Data Studio and leave the original value for the rest; for example:

CASE
  WHEN (source/medium = “lnkd.IN|linkedin.*”) THEN “Linkedin”
  ELSE “”
END

Can the ELSE be blank to keep the same original value?

logi-kal
  • 7,107
  • 6
  • 31
  • 43
  • Could you elaborate by providing a publicly editable Google Data Studio Report (additionally, a Google Sheet if it's the data set) of the scenario (using sample data that shows 1) Input values (~10 rows) 2) Expected output 3) An attempt at solving the issue)? It would help users visualise the issue and test out suggestions on a specific use case with objective right / wrong answers. Without a [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) it would be difficult to pinpoint a suggestion and the issue, e.g. Data Set, Data Source, Report, Fields, Chart – Nimantha Feb 13 '22 at 16:16

2 Answers2

0

Put the column that you're updating in the ELSE clause, so it will assign the original value back to the column.

SET columnname = CASE WHEN (`source/medium` RLIKE 'lnkd\\.in|linkedin\\.') THEN 'Linkedin' ELSE columnname END
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Note that in Google Data Studio, `SET` as well as `RLIKE` are currently not implemented, thus adding the respective commands / functions, which would result in error messages such as: `Syntax error: Unexpected "SET"` or `Syntax error: Expected ")" but got...` – Nimantha Mar 12 '22 at 10:03
0

Your else clause should just be the column that you're testing on if you want it to remain unchanged. For example if your column name is "source/medium", it would be like this:

CASE WHEN (source/medium = “lnkd.in|linkedin.*”) THEN “Linkedin” ELSE source/medium END
Matt Hamrick
  • 759
  • 5
  • 10
  • Note that using the calculated field in the answer would (currently) result in an error that states: `Syntax error: Illegal input character. Check that your formula does not contain smart quotes.` – Nimantha Mar 12 '22 at 10:10