Skip to Content

Reuse of Calculated Columns in CDS View

Oct 10, 2017 at 09:43 AM


avatar image


I should use a calculated columns for other calcs in my CDS View, for example

Order.GrossValue as GrossValue,

Order.NetValue as NetValue,

GrossValue - NetValue = Gain

Gain / 1000 = Gain1000

Gain is not usable because is not known as column.

Is there any Annotation or can I know which is the best practice to reuse calc columns in the same CDS view.

Thank you

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
ERALPER YILMAZ Dec 01, 2017 at 07:56 AM

It is not possible to refer to a calculated field in an other calculated field unfortunately.

So you have to do the same calculation in the second field as well

For example, following code can be used in a CDS view

  netwr + mwsbk as total,
  ( netwr + mwsbk ) * 1000 as total1000
from vbrk

10 |10000 characters needed characters left characters exceeded
ERALPER YILMAZ Oct 26, 2017 at 06:38 AM

Hello Antonio,

Instead of creating calculated values in CDS views, if possible you can define these values in tables as computed columns

Here is an example

create column table Table1 (
    Multiplicand int,
    Multiplier int,
    Product int as Multiplicand * Multiplier
insert into Table1 values (2,5);

select * from Table1;

Here is the result

Does it help?

Or you need it really on CDS views? If so, can you give more detail with a sample code

sql.png (3.5 kB)
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thanks but I need to calc the value in CDS, the only possible way is to create a CDS on top of the first one and calc the value.