Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Concatenate dataset fields if and only if they match a value
kalpana5
<p>I have a dataset in whcih there are 20 fields to display , client asked to create a field and contaenante 10 fields out of 20 if and only if those fields have a value of 'Yes', those 10 fields either have 'Yes ' or 'No ' value, concatenate fields seperated by comma only of they have value of 'Yes'. Could you please suggest a way in Birt, BirtComp function is allowing me to compare only 1 field in my case there are 10 fields could you suggest , really appreciate .
</p>
Find more posts tagged with
Comments
micajblock
<p>This should work:</p><div><pre class="_prettyXprint">if (row["col1"] == "Yes" && row["col2"] == "Yes" && row["col3"] == "Yes" && row["col4"] == "Yes" && row["col5"] == "Yes" && row["col6"] == "Yes" && row["col7"] == "Yes" && row["col8"] == "Yes" && row["col9"] == "Yes" && row["col10"] == "Yes" ) {"Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes";}else {null}</pre></div>
kalpana5
<blockquote class="ipsBlockquote" data-author="mblock" data-cid="127272" data-time="1397175710"><div><p> </p><p>This should work:</p><div><pre class="_prettyXprint">if (row["col1"] == "Yes" && row["col2"] == "Yes" && row["col3"] == "Yes" && row["col4"] == "Yes" && row["col5"] == "Yes" && row["col6"] == "Yes" && row["col7"] == "Yes" && row["col8"] == "Yes" && row["col9"] == "Yes" && row["col10"] == "Yes" ) {"Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes";}else {null}</pre></div><p> </p></div></blockquote><p>Hello Sir,</p><p> </p><p>Thanks for the reply, I need to concatenate the corresponding label names for those columns, what should I do in that case , for example row[1] = 'GP', row[2] = 'HP' if they have value of 'Yes' only I should concatenate 'GP' , 'HP', please suggest.</p>
kalpana5
<blockquote class="ipsBlockquote" data-author="kalpana5" data-cid="127273" data-time="1397177256"><div><p>Hello Sir,</p><p> </p><p>Thanks for the reply, I need to concatenate the corresponding label names for those columns, what should I do in that case , for example row[1] = 'GP', row[2] = 'HP' if they have value of 'Yes' only I should concatenate 'GP' , 'HP', please suggest.</p></div></blockquote><p>Sorry it might be a dumb question, so bascially in place of 'Yes' I will be putting label names, but if I use && operator if and only if all the values == 'Yes' it will display string , what if any of the values = 'No' then this condition will not work , could you please suggest, really appreciate your inputs.</p><p> </p><p>Thanks.</p>
micajblock
<p>The '&&' operator is an 'AND;' operator. So only if ALL the values are 'Yes' it will display the string, otherwise it is null and will display nothing. What you put in that string is up to you. I thought you said display the 10 values. Since they are Yes I just displayed Yes 10 times.</p>
kalpana5
Ok , got you sorry for the confusion, actually I would like to check which values are 'YES', out of those 10 values and display only those values which have a value of 'YES', each field can either have 'YES' or 'NO', would like to display only the fields with 'YES'. Please suggest.
Thanks
micajblock
<p>Same concept, just different logic. Put code similar to below in your expression.</p><div><pre class="_prettyXprint">var myArray = new Array();if (row["col1"] == "Yes") {myArray.push("col1");}if (row["col2"] == "Yes") {myArray.push("col2");}if (row["col3"] == "Yes") {myArray.push("col3");}if (row["col4"] == "Yes") {myArray.push("col4");}if (row["col5"] == "Yes") {myArray.push("col5");}if (row["col6"] == "Yes") {myArray.push("col6");}if (row["col7"] == "Yes") {myArray.push("col7");}if (row["col8"] == "Yes") {myArray.push("col8");}if (row["col9"] == "Yes") {myArray.push("col9");}if (row["col10"] == "Yes") {myArray.push("col10");}myArray.join();</pre></div>
kalpana5
<blockquote class="ipsBlockquote" data-author="mblock" data-cid="127307" data-time="1397245738"><div><p> </p><p>Same concept, just different logic. Put code similar to below in your expression.</p><div><pre class="_prettyXprint">var myArray = new Array();if (row["col1"] == "Yes") {myArray.push("col1");}if (row["col2"] == "Yes") {myArray.push("col2");}if (row["col3"] == "Yes") {myArray.push("col3");}if (row["col4"] == "Yes") {myArray.push("col4");}if (row["col5"] == "Yes") {myArray.push("col5");}if (row["col6"] == "Yes") {myArray.push("col6");}if (row["col7"] == "Yes") {myArray.push("col7");}if (row["col8"] == "Yes") {myArray.push("col8");}if (row["col9"] == "Yes") {myArray.push("col9");}if (row["col10"] == "Yes") {myArray.push("col10");}myArray.join();</pre></div><p> </p></div></blockquote><p>Thank You so much.</p>