简体   繁体   中英

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.

I've built calculated fields like this:

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

that result in this within a table:

Field 1

Field 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM