Add a new column based on condition check

  • Goal: I have column A, B, and C in my table component table1.
    -Columns B and C are also calculated columns.

  • I want to check a condition and add a new column D i.e. if A>20 then D= B+C else D= B*C.

  • Steps: I tried building the new custom column and populating it using transformer but this isn't working.
    rough transformer code.
    const newvalue = formatDataAsArray(table1.data).map(row => ({
    ...row,
    D: row.A > 20 ? row.B + row.C : row.B * row.C
    }));
    return newvalue;
    In the value section of the table component, what should I add here ?
    transformer.data[i].newvalue

  • Details: We are on self-hosted retool.

Could you please help if this is the right approach or I need to change something ?

1 Like

Hello @Anjali_S ,

Here is an example of how you can set the value of the D column using the transformer.

Feel free to ask if you need further assistance or have additional questions. We're here to help!

4 Likes