cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
See how to use to use Text Explorer to glean valuable information from text data at April 25 webinar.
Choose Language Hide Translation Bar
View Original Published Thread

Concatenate columns with empty cells

JMP_fan
Level I

Hi all,

I have a dataset with different columns that have some empty random cells (like the example in the table below). I would like to concatenate the values of the different columns and use the "_" to separate the content of the cells only if the content of the cells is different from empty value (as in column "concat" below). Does anyone have a suggestion on a how to to this operation in a smart way?

Thanks for your help! 

 

NameAgeSexConcat

Mads

31 Mads_31
  MM
John25 John_25
Julia19FJulia_19_F
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User


Re: Concatenate columns with empty cells

Here is one way of writing the formula

colList = {"Column 1", "Column 2", "Column 3"};
x = "";
For( i = 1, i <= N Items( colList ), i++,
	If( As Column( colList[i] ) != "",
		If( x != "", x = x || "_" );
		x = x || Char( As Column( colList[i] ) );
	)
);
Trim( x );
Jim

View solution in original post

3 REPLIES 3


Re: Concatenate columns with empty cells

You should be able to use a simple function in a new column Concat:

 

formula.PNG

txnelson
Super User


Re: Concatenate columns with empty cells

Here is one way of writing the formula

colList = {"Column 1", "Column 2", "Column 3"};
x = "";
For( i = 1, i <= N Items( colList ), i++,
	If( As Column( colList[i] ) != "",
		If( x != "", x = x || "_" );
		x = x || Char( As Column( colList[i] ) );
	)
);
Trim( x );
Jim


Re: Concatenate columns with empty cells

Hi, here is yet another formula.

Concat Items( Words( :Name || "," || :Age || "," || :Sex, "," ), "_" )

Cheers,

Brady