Calculate the string in the column like "50x8" to 400

Dear community friend,

I am new to this community. I have found many solutions here for the problems in my work. I really appreciate this place.

Today I bump into a problem I cannot find any history about it. I screenshot my original column and my desired result as below. Basically, I have a pack size column and I want to calculate the string in the original column and return the mathematical result. I have a rough idea that I can split the column by the β€œx” can multiply the two new columns. I wonder if there is any direct or smarter solution. Thank you.

image

Hi @Jason_Xie

There are a lot of ways to solve this, with native nodes and through code. If you’re looking for a direct way, you can use a Column Expression node and apply:

var number = column("column1").split('x');
var result = 1;
for (var i = 0; i < number.length; i++) {
    result *= parseFloat(number[i]);
}

2 Likes