'How to concat two fields with a new line in the middle in Google Data Studio?

First, this is not the same as How to make a new line in Google Data Studio in the exception? because that one is for writing a new connector and I am not trying to do that.

I want to concat two fields in a table column and put a new-line in the middle. Using \n does not seem to work.



Solution 1:[1]

I've built calculated fields like this:

concat([Field1],"\n","\n",[Field2])

that result in this within a table:

Field 1

Field 2

Solution 2:[2]

For some reason, when using a custom data source concatenating the new line character would not work under any tests I performed (I used every text manipulation function they have). That approach, which matches Kellie's answer was:

concat(field1, '\n\n', field2)

This only works with google analytics data sources where there isn't a date range dimension (I didn't test gsheets/others) and you must have "wrap text" on the table body enabled. The work-around I found was to *NOT use data studio formatting in that you can put this in your data connector query/stored procedure. A PostgreSQL example:

select 
concat(field1, e'\n\n', field2) as newfield
from datatable;

Hopefully the datastudio team will fix this bug in the future (edit: the bug was with pivot tables, in that they do not recognize the new lines).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kellie Ballard
Solution 2