Reputation: 335
I would like to concatenate a number
and text
based on a condition. For example:
CASE WHEN quantity = 1 THEN CONCAT(quantity, 'Item') ELSE CONCAT(quantity, 'Items') END
Result:
1 Item
2 Items
3 Items
...
20 Items
Presently, THEN/ELSE statements do not accept functions. Is there an alternative method to achieve the above result in data studio?
Upvotes: 1
Views: 1556
Reputation: 6471
One way it can be achieved is by creating the below 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
function to ensure that 1 Items
is replaced by 1 Item
:
REGEXP_REPLACE(CONCAT(quantity, " Items"), "^(1 Items)$", "1 Item")
Google Data Studio Report and a GIF to elaborate:
Upvotes: 1