Adding a new column to a data table from a calculation based on two different columns in the same row

I was wondering if it was possible to add a new column to a data table in a Visualize from a calculation based on two different columns in the same row

Say I have two columns Calls A and Calls B I want to create a third column say Total Calls which is the sum of Calls A + Calls B.

Call A is a Metric sum of calls_a
Call B is a Metric sum of calls_b

i.e.

       Calls A | Calls B | Total Calls
Ottawa    1         2           3
Toronto   5         4           9
Nunavik   0         0           0

You can create a new script field ( type: painless ) . under Management / index patterns

Select the index pattern u want to write the script field...

def totalCalls = doc['Calls A'].value + doc ['Calls B'].value; return totalCalls;

Hello,

Thanks for your quick reply and it work perfectly. I have a follow up question.

If I wanted to create another new column call Call A Percentage, what would the script look like for that?

I think I'm close, but don't know what syntax to put around 'totalCalls ':
def call_a_percentage = doc['Calls A'].value / 'totalCalls '; return call_a_percentage ;

Thanks again for your help!

So, u want to format the value of "Call A Percentage" field ?

just select the field (under fields) and click pencil icon and change the format to percentage then click save field..

Actually I want to create another new column like the following, where I divide Calls A by Total Calls

       Calls A | Calls B | Total Calls | Call A Percentage
Ottawa    1         2           3             33.3%
Toronto   5         4           9             55.6%
Nunavik   0         0           0             0.0%

Create a new script field "Call A Percentage" (Type: painless)

def call_a_percentage = doc['Calls A'].value / 'totalCalls ';
click save

Then just select the " call_a_percentage "field (under fields) and click pencil icon and change the format to percentage then click save field..This should give you the Call A Percentage..

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.