Hello, I’m new to Redash, my query is very simple, I need to calculate the difference value as decimal
However, I found out Redash always display as 0.00 for this particular field. I also noticed whenever the result is < 1, it shows 0.00. The rouding decimal also not correct, the 2 decimal always showing as .00

ROUND((currentdataset.num_total-olddataset.num_total)/olddataset.num_total, 2) AS difference

very appreciate if any of you can provide a quick tips how to calculate this field correctly in redash table. I no need the data for visualization.

Welcome in th Redash community forum.

According to the database you are using you may have to cast both part’s of the division in another numeric type else than integer.

Thanks Mathieu. Is there a sample to refer? If not mistaken, I had casted but it returned error, not too sure I casted in a right way

What database are you using ?

For example with PostgreSQL :

 select 4/3 , 4/3::numeric, 4::float/3

Returns

| ?column? |           ?column? |           ?column? |
|----------|--------------------|--------------------|
|        1 | 1.3333333333333333 | 1.3333333333333333 |

/ performs an integer division if both operands are integers.

many thanks Mathieu. You got it!!! It works!!!

2 Likes