Solved

calculated column t1?

  • 26 August 2022
  • 5 replies
  • 113 views

Userlevel 1
Badge +4

Do you need to use t1 with the calculated column type?
 

I have the following calculated field code : btw_percentage / 100 + 1.00
However when I tried to add t1. to it. The database gave an error. 
But the code as it is written above doesn't work.

Does anyone know how to handle this?


 

icon

Best answer by Mark Jongeling 26 August 2022, 13:47

View original

5 replies

Userlevel 7
Badge +23

Hi Maarten,

Specifying t1 is not needed as the column is in the context of the table already. No other tables are available, thus always selecting out of the same table.

What is exactly not working? 

One thing I can think of is that btw_percentage has a datatype of type INT. This will not go well with dividing and such. 

Userlevel 1
Badge +4

@Mark Jongeling  btw_percentage is indeed of the datatype int

Userlevel 7
Badge +23

SQL server will see 21 / 100, for example, as 0, then + 1.00 is 1.00. This is not intended. When needing calculations like this, you'll need to ensure the tax percentage is of type Numeric (or similar).

Userlevel 5
Badge +16

As a rule:

  • Expression fields user t1.column_name
  • Calculated columns (no prefix) column_name
  • Calculated columns (via function) @column_name

As you to your code, when it's an INT you sometimes need to push decimals, I guess in this case you would like to make from 21% a factor 1,21 right?

(100.0 + btw_percentage) / 100.0 

If above still gives an error you can always cast btw_percentage as a decimal(5,2) for example. 

Userlevel 5
Badge +8

Please see this related idea, which will be available in the next platform release: 

 

Reply