Choose Language Hide Translation Bar
powerpuff
Community Trekker

Comparing row values

I have a table which has 2 columns Term and Multiply which looks something like this:

 

Capture1.PNG

I want to somehow be able to read the column "Term" and check the following:

1) If the term in the "Term" column is not multiplied by anything (like Name, Place, Animal and Thing in the above table), then multiply the value in the "Multiply" column by 2.

2) If the term in the "Term" column is multiplied by any other term (like Place*Thing in the above table), then multiply the value in the "Multiply" column by 2.

3) If the term in the "Term" column is multiplied by itself(like Name*Name and Animal*Animal in the above table), then keep the value in "Multiply" column as it is. 

 

The resulting table would look like this:

Capture.PNG

Can this be done using jsl? Thanks

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
ih
ih
Community Trekker

Re: Comparing row values

Maybe something like this:

 

New Table( "Multiply",
	Add Rows( 8 ),
	New Column( "Term", Character, "Nominal",
		Set Values( {"Name", "Place", "Animal", "Thing", "Name*Name", "Place*Thing",
			"Animal", "Animal*Animal"} )
	),
	New Column( "Multiply", Numeric, "Continuous",
		Format( "Best", 12 ),
		Set Values( [0.43, 0.5567, 0.056, 0.236, 0.15503, 0.44479, 0.7789, 0.22754] )
	),
	New Column( "Result",
		Expression,
		"None",
		Formula(
			mtch = Regex Match( :Term, "([^*]*)\*([^*]*)" );
			If(
				N Items( mtch ) == 0, :Multiply * 2,
				N Items( mtch ) == 3,
					If( mtch[2] == mtch[3],
						:Multiply,
						:Multiply * 2
					)
			);
		)
	)
)

View solution in original post

2 REPLIES 2
cwillden
Super User

Re: Comparing row values

deleted my response because I realized I didn’t answer the right question
-- Cameron Willden
0 Kudos
ih
ih
Community Trekker

Re: Comparing row values

Maybe something like this:

 

New Table( "Multiply",
	Add Rows( 8 ),
	New Column( "Term", Character, "Nominal",
		Set Values( {"Name", "Place", "Animal", "Thing", "Name*Name", "Place*Thing",
			"Animal", "Animal*Animal"} )
	),
	New Column( "Multiply", Numeric, "Continuous",
		Format( "Best", 12 ),
		Set Values( [0.43, 0.5567, 0.056, 0.236, 0.15503, 0.44479, 0.7789, 0.22754] )
	),
	New Column( "Result",
		Expression,
		"None",
		Formula(
			mtch = Regex Match( :Term, "([^*]*)\*([^*]*)" );
			If(
				N Items( mtch ) == 0, :Multiply * 2,
				N Items( mtch ) == 3,
					If( mtch[2] == mtch[3],
						:Multiply,
						:Multiply * 2
					)
			);
		)
	)
)

View solution in original post