Solved

Formula to concatenate multiple boolean fields with a delimiter

Posted on 2016-09-12
4
42 Views
Last Modified: 2016-09-14
Gurus,

I need a formula to concatenate and separate 6 Boolean fields together where one or more may be true.

For instance, Field 1 may be True or False.  If True then "Field 1" else ""

I need the formula output result to be:
Field 1
or
Field 2
or
Field 1, Field 2
or
Field 2, Field 4

etc, etc.  I'm adding a comma to separate the values for readability.

Here's the formula I'm using that's close but it's adding a "comma" after conditions where only one field is True


Local StringVar strOut;

if Not(isnull({CONTACT.Automation})) AND {CONTACT.Automation} = True then
    strOut := "RA" & ", ";
if Not(isnull({CONTACT.Automation})) AND {CONTACT.Hardfacing} = True then
    strOut := strOut + "RH" & ", ";
if Not(isnull({CONTACT.Automation})) AND {CONTACT.Industrial} = True then
    strOut := strOut + "IND" & ", ";
if Not(isnull({CONTACT.Automation})) AND {CONTACT.PMA} = True then
    strOut := strOut + "PMA" & ", ";
if Not(isnull({CONTACT.Automation})) AND {CONTACT.Tactical} = True then
    strOut := strOut + "TAC" & ", ";
if Not(isnull({CONTACT.Automation})) AND {CONTACT.Underwater} = True then
    strOut := strOut + "UW" & ", ";
Mid(strOut,1)


What am I missing?  Thanks in advance!!
0
Comment
Question by:SStroz
  • 2
4 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 41795125
You could change the last line to

Left(strOut, Length(strOut)-1)

or

Mid(strOut, 1, Length(strOut)-1)


mlmcc
0
 
LVL 34

Accepted Solution

by:
James0628 earned 500 total points
ID: 41795770
Another option is to put the comma in front of each value, and then use Mid to exclude the first comma from the output.

Local StringVar strOut;

if Not(isnull({CONTACT.Automation})) AND {CONTACT.Automation} = True then
    strOut :=  ", " + "RA";
if Not(isnull({CONTACT.Automation})) AND {CONTACT.Hardfacing} = True then
    strOut := strOut + ", " + "RH";
if Not(isnull({CONTACT.Automation})) AND {CONTACT.Industrial} = True then
    strOut := strOut + ", " + "IND";
if Not(isnull({CONTACT.Automation})) AND {CONTACT.PMA} = True then
    strOut := strOut + ", " + "PMA";
if Not(isnull({CONTACT.Automation})) AND {CONTACT.Tactical} = True then
    strOut := strOut + ", " + "TAC";
if Not(isnull({CONTACT.Automation})) AND {CONTACT.Underwater} = True then
    strOut := strOut + ", " + "UW";

if Length (strOut) > 2 then
  Mid(strOut,3)
else
  strOut

Open in new window


 James
0
 
LVL 7

Author Comment

by:SStroz
ID: 41797121
mlmcc, your formula gave me this error:

String length is less than 0 or not an integer


I used James solution for this one.


Many thanks to both of you!!!
0
 
LVL 34

Expert Comment

by:James0628
ID: 41797609
You're welcome.

 FWIW, the error on mlmcc's formula was probably from records where none of your conditions were true, so you ended up with an empty string.  Then Length (strOut) - 1 would give you -1, which would give you that error.

 You could handle that using

if Length (strOut) > 1 then
  Left(strOut, Length(strOut)-1)

  or

if Length (strOut) > 1 then
  Mid(strOut, 1, Length(strOut)-1)


 James
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to add a total 6 33
across tab - Distinct Count - Crystal Reports 2 76
Need to learn crystal reports 7 56
Formatting number to Text Format DDDDDDDDCC 1 30
Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now