Expand my Community achievements bar.

SOLVED

Removing a comma on my calculated field

Avatar

Level 4

Hi All, I've created the following calculated field that works lovely except for the fact that when the first field in the calculation is empty, the field displays a comma before any of the following fields. Not a big deal but kind of an eyesore. How would I go about removing that first comma from the following calculation if the first field is blank?

 

CONCAT({DE:CL 1:name},IF(ISBLANK({DE:CL 2:name}),"", ", "),{DE:CCL 2:name},IF(ISBLANK({DE:CL 3:name}),"", ", "),{DE:CL 3:name},IF(ISBLANK({DE:CUL 1:name}),"", ", "),{DE:CUL 1:name},IF(ISBLANK({DE:CUL 2:name}),"", ", "),{DE:CUL 2:name},IF(ISBLANK({DE:CUL 3:name}),"", ", "),{DE:CUL 3:name},IF(ISBLANK({DE:PL 1:name}),"", ", "),{DE:PL 1:name},IF(ISBLANK({DE:PL 2:name}),"", ", "),{DE:PL 2:name},IF(ISBLANK({DE:PL 3:name}),"", ", "),{DE:PL 3:name})
Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

I would simplify a little and then remove the first char. 
Note that i ALWAYS have a comma followed by a value - or nothing. That means I can safely remove the first char (which will always be a comma) 

SUBSTR(IF(ISBLANK({DE:CL 1:name}),"",","+{DE:CL 1:name})+
IF(ISBLANK({DE:CL 2:name}),"",","+{DE:CL 2:name})+
IF(ISBLANK({DE:CL 3:name}),"",","+{DE:CL 3:name})+
IF(ISBLANK({DE:CUL 1:name}),"",","+{DE:CUL 1:name})+
IF(ISBLANK({DE:CUL 2:name}),"",","+{DE:CUL 2:name})+
IF(ISBLANK({DE:CUL 3:name}),"",","+{DE:CUL 3:name})+
IF(ISBLANK({DE:PL 1:name}),"",","+{DE:PL 1:name})+
IF(ISBLANK({DE:PL 2:name}),"",","+{DE:PL 2:name})+
IF(ISBLANK({DE:PL 3:name}),"",","+{DE:PL 3:name}),1)

View solution in original post

4 Replies

Avatar

Level 8

Hi @OmahaOmaha - Could you try this? I'm not sure if there is a better and easy way to do this which is manageable.

CONCAT(
IF(!ISBLANK({DE:CL 1:name}), {DE:CL 1:name}, ""),
IF(!ISBLANK(CONCAT({DE:CL 1:name})) & !ISBLANK({DE:CL 2:name}), ", ", ""),
IF(!ISBLANK({DE:CL 2:name}), {DE:CL 2:name}, ""),
IF(!ISBLANK(CONCAT({DE:CL 1:name}, {DE:CL 2:name})) & !ISBLANK({DE:CL 3:name}), ", ", ""),
IF(!ISBLANK({DE:CL 3:name}), {DE:CL 3:name}, ""),
IF(!ISBLANK(CONCAT({DE:CL 1:name}, {DE:CL 2:name}, {DE:CL 3:name})) & !ISBLANK({DE:CUL 1:name}), ", ", ""),
IF(!ISBLANK({DE:CUL 1:name}), {DE:CUL 1:name}, ""),
IF(!ISBLANK(CONCAT({DE:CL 1:name}, {DE:CL 2:name}, {DE:CL 3:name}, {DE:CUL 1:name})) & !ISBLANK({DE:CUL 2:name}), ", ", ""),
IF(!ISBLANK({DE:CUL 2:name}), {DE:CUL 2:name}, ""),
IF(!ISBLANK(CONCAT({DE:CL 1:name}, {DE:CL 2:name}, {DE:CL 3:name}, {DE:CUL 1:name}, {DE:CUL 2:name})) & !ISBLANK({DE:CUL 3:name}), ", ", ""),
IF(!ISBLANK({DE:CUL 3:name}), {DE:CUL 3:name}, ""),
IF(!ISBLANK(CONCAT({DE:CL 1:name}, {DE:CL 2:name}, {DE:CL 3:name}, {DE:CUL 1:name}, {DE:CUL 2:name}, {DE:CUL 3:name})) & !ISBLANK({DE:PL 1:name}), ", ", ""),
IF(!ISBLANK({DE:PL 1:name}), {DE:PL 1:name}, ""),
IF(!ISBLANK(CONCAT({DE:CL 1:name}, {DE:CL 2:name}, {DE:CL 3:name}, {DE:CUL 1:name}, {DE:CUL 2:name}, {DE:CUL 3:name}, {DE:PL 1:name})) & !ISBLANK({DE:PL 2:name}), ", ", ""),
IF(!ISBLANK({DE:PL 2:name}), {DE:PL 2:name}, ""),
IF(!ISBLANK(CONCAT({DE:CL 1:name}, {DE:CL 2:name}, {DE:CL 3:name}, {DE:CUL 1:name}, {DE:CUL 2:name}, {DE:CUL 3:name}, {DE:PL 1:name}, {DE:PL 2:name})) & !ISBLANK({DE:PL 3:name}), ", ", ""),
IF(!ISBLANK({DE:PL 3:name}), {DE:PL 3:name}, "")
)

Avatar

Level 8

Please try this as well. This code is more manageable.

LEFT(
    CONCAT(
        IF(ISBLANK({DE:CL 1:name}), "", CONCAT({DE:CL 1:name}, ", ")),
        IF(ISBLANK({DE:CL 2:name}), "", CONCAT({DE:CL 2:name}, ", ")),
        IF(ISBLANK({DE:CL 3:name}), "", CONCAT({DE:CL 3:name}, ", ")),
        IF(ISBLANK({DE:CUL 1:name}), "", CONCAT({DE:CUL 1:name}, ", ")),
        IF(ISBLANK({DE:CUL 2:name}), "", CONCAT({DE:CUL 2:name}, ", ")),
        IF(ISBLANK({DE:CUL 3:name}), "", CONCAT({DE:CUL 3:name}, ", ")),
        IF(ISBLANK({DE:PL 1:name}), "", CONCAT({DE:PL 1:name}, ", ")),
        IF(ISBLANK({DE:PL 2:name}), "", CONCAT({DE:PL 2:name}, ", ")),
        IF(ISBLANK({DE:PL 3:name}), "", CONCAT({DE:PL 3:name}, ", "))
    ),
    LEN(
        CONCAT(
            IF(ISBLANK({DE:CL 1:name}), "", CONCAT({DE:CL 1:name}, ", ")),
            IF(ISBLANK({DE:CL 2:name}), "", CONCAT({DE:CL 2:name}, ", ")),
            IF(ISBLANK({DE:CL 3:name}), "", CONCAT({DE:CL 3:name}, ", ")),
            IF(ISBLANK({DE:CUL 1:name}), "", CONCAT({DE:CUL 1:name}, ", ")),
            IF(ISBLANK({DE:CUL 2:name}), "", CONCAT({DE:CUL 2:name}, ", ")),
            IF(ISBLANK({DE:CUL 3:name}), "", CONCAT({DE:CUL 3:name}, ", ")),
            IF(ISBLANK({DE:PL 1:name}), "", CONCAT({DE:PL 1:name}, ", ")),
            IF(ISBLANK({DE:PL 2:name}), "", CONCAT({DE:PL 2:name}, ", ")),
            IF(ISBLANK({DE:PL 3:name}), "", CONCAT({DE:PL 3:name}, ", "))
        )
    ) - 2
)



Avatar

Correct answer by
Community Advisor

I would simplify a little and then remove the first char. 
Note that i ALWAYS have a comma followed by a value - or nothing. That means I can safely remove the first char (which will always be a comma) 

SUBSTR(IF(ISBLANK({DE:CL 1:name}),"",","+{DE:CL 1:name})+
IF(ISBLANK({DE:CL 2:name}),"",","+{DE:CL 2:name})+
IF(ISBLANK({DE:CL 3:name}),"",","+{DE:CL 3:name})+
IF(ISBLANK({DE:CUL 1:name}),"",","+{DE:CUL 1:name})+
IF(ISBLANK({DE:CUL 2:name}),"",","+{DE:CUL 2:name})+
IF(ISBLANK({DE:CUL 3:name}),"",","+{DE:CUL 3:name})+
IF(ISBLANK({DE:PL 1:name}),"",","+{DE:PL 1:name})+
IF(ISBLANK({DE:PL 2:name}),"",","+{DE:PL 2:name})+
IF(ISBLANK({DE:PL 3:name}),"",","+{DE:PL 3:name}),1)

Avatar

Level 8

Brilliant!