Multiply 2 variables in Datatable

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

Hi and welcome to our community!

didn't test, checked the documentation:

maybe you need to switch from {custom_price} to {var "custom_price"}?

Best,
Matthias

Hi Matthias,
thanks for your reply.
I've already defined the variable as described in Edit workpads => 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})"}

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
2 Likes

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