# Multiply 2 variables in Datatable

**URL:** <https://discuss.elastic.co/t/multiply-2-variables-in-datatable/271341>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [April 27, 2021, 9:02am UTC](https://discuss.elastic.co/t/multiply-2-variables-in-datatable/271341 "2021-04-27T09:02:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NightWalker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nightwalker/32/81992_2.png) [@NightWalker](https://discuss.elastic.co/u/NightWalker)\
**Post date:** [April 27, 2021, 9:02am UTC](https://discuss.elastic.co/t/multiply-2-variables-in-datatable/271341/1 "2021-04-27T09:02:23Z")

</div>

Hi,  
I'm trying to do something pretty simple but have a hard time to get it work.  
I've an global variable {custom\_price} and want to multiply it with each column value. I've tried every combination which came in my mind but nothing works

Simplified example:

```
 var {custom_price} //Custom global variable which is set on the whole Workpad

filters
| essql 
  query="SELECT HISTOGRAM(created, INTERVAL 1 MONTH) as mydate, SUM(number_of_items) as items_count FROM \"mytable*\" WHERE error_code=0 GROUP BY HISTOGRAM(created, INTERVAL 1 MONTH) ORDER BY mydate DESC"
| mapColumn name="Total" fn={math "multiply(items_count,{custom_price})" |formatnumber "$0,0.00"} // I want to implement something like this
| mapColumn name="Total2" fn={getCell items_count| math "multiply(value,3)" |formatnumber "$0,0.00"} //this works but i can't use the variable here
| table
| render 

```

any ideas how this can be done?  
Thanks

---

<div class="post-metadata">

**Author:** ![matw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matw/32/13913_2.png) [@matw](https://discuss.elastic.co/u/matw)\
**Post date:** [April 27, 2021, 10:12am UTC](https://discuss.elastic.co/t/multiply-2-variables-in-datatable/271341/2 "2021-04-27T10:12:24Z")

</div>

Hi and welcome to our community!

didn't test, checked the documentation:

> **[Edit workpads | Kibana Guide \[master\] | Elastic](https://www.elastic.co/guide/en/kibana/master/edit-workpads.html)**

maybe you need to switch from {custom\_price} to {var "custom\_price"}?

Best,  
Matthias

---

<div class="post-metadata">

**Author:** ![NightWalker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nightwalker/32/81992_2.png) [@NightWalker](https://discuss.elastic.co/u/NightWalker)\
**Post date:** [April 27, 2021, 12:04pm UTC](https://discuss.elastic.co/t/multiply-2-variables-in-datatable/271341/3 "2021-04-27T12:04:11Z")

</div>

Hi Matthias,  
thanks for your reply.  
I've already defined the variable as described in [Edit workpads =\> Create variables](https://www.elastic.co/guide/en/kibana/master/edit-workpads.html#create-variables)

I know that something with my notation is wrong but can't figure ouw how to write it correctly. I've tried multiple notations but it always gives me a syntax Error

```
| mapColumn name="Total" fn={math "multiply(items_count,{custom_price})"}
| mapColumn name="Total" fn={math "multiply(items_count,{var "custom_price"})"}
| mapColumn name="Total" fn={math "multiply(items_count,var {custom_price})"} 
| mapColumn name="Total" math={getCell items_count | "multiply(value, var {custom_price})"}
```

---

<div class="post-metadata">

**Author:** ![Felix\_Roessel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felix_roessel/32/41623_2.png) [@Felix\_Roessel](https://discuss.elastic.co/u/Felix_Roessel)\
**Post date:** [April 28, 2021, 9:24am UTC](https://discuss.elastic.co/t/multiply-2-variables-in-datatable/271341/4 "2021-04-28T09:24:57Z")

</div>

This is a working example using variable instead of mapColumn, but its the same notion

```
filters

| demodata

| var_set "val1" value=2

| var_set "val2" value=3

| var_set "result" value={math {string "multiply( " {var "val1"} ", " {var "val2"} " )"}}

| markdown "Test: " {var "result"}

| render
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 26, 2021, 9:25am UTC](https://discuss.elastic.co/t/multiply-2-variables-in-datatable/271341/5 "2021-05-26T09:25:59Z")

</div>

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