根据 Google Data Studio 中的条件连接数字和文本

Concatenate Number and Text based on condition in Google Data Studio

我想根据条件连接 numbertext。例如:

CASE WHEN quantity = 1 THEN CONCAT(quantity, 'Item') ELSE CONCAT(quantity, 'Items') END

结果:

1 Item
2 Items
3 Items
...
20 Items

目前,THEN/ELSE 语句不接受函数。是否有其他方法可以在 Data Studio 中实现上述结果?

实现它的一种方法是创建以下 Calculated Field which uses the CONCAT function to join the Quantity field with the text Items (note that the single space before Items is intentional) and then the REGEXP_REPLACE 函数以确保 1 Items1 Item 替换:

REGEXP_REPLACE(CONCAT(quantity, " Items"), "^(1 Items)$", "1 Item")

Google Data Studio Report 和一张 GIF 来详细说明: