web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Why computed column has to be string?

(0) ShareShare
ReportReport
Posted on by

Hi all,

Anyone can give me some understanding why computed column should always be a string ?

Noted in Microsoft Docs also specify this, but I just want to know the reason for this ?

https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/data-entities/data-entity-computed-columns-virtual-fields#properties-of-unmapped-fields 

Thanks,

I have the same question (0)
  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi,

    The computed column is not always string. It could be Int, Int64, Real, Enum etc.

    The computed field data method, however, should return a string value as it is CAST into the desired data type. The method is converted into TSQL as per the link you provided.

    You can check SalesInvoiceHeaderV2Entiity\TotalDiscountAmount field as an example of a computed field of data type Real.

  • Verified answer
    Jeremy_Mounet Profile Picture
    170 on at

    Hello

    As Gujan said, computed columns are not always a string. It contains the "result" of a computed columns "method", this one bound on the view by a property of the computed field.

    On the other hand, the computed column method should return always a string because the result of its return during synchronization process, will be the SQL code part to execute for the column on the global SQL query of the view. A computed column method is also not something to code for a X++ execution but something to write SQL expression (by using SysComputed class framework for instance).

    For this kind of object and for training, I suggest to edit in SQL some views with computed columns with SSMS to see the result of the synchronization.

    Hope it helps.

    Jérémy.

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    The computed column definition must be a string because it must return a T-SQL statement that is then executed to populate the values to the actual computed column. 

    Unlike display methods, which contain code and return some value, the computed column x++ definition returns "code" (T-SQL) statement. The x++ code is executed in db sync, unlike a display method which is executed during runtime. In computed columns the T-SQL statement is the code that is executed during runtime (in the database). 

  • Verified answer
    Joris dG Profile Picture
    17,775 on at

    What Nikolaos said. It's important to understand the computed column's _method_ will NEVER execute when the view is used. It's executed ONCE when the database sync runs, and its output goes straight into the SQL view's statement. It is not dynamic... The string you produce will be executed in SQL every time the view executes.

    I blogged about this many years ago when this feature was introduced in AX2012. This information is still accurate: daxmusings.codecrib.com/.../computed-view-columns-in-ax-2012.html

  • Verified answer
    Faisal Fareed Profile Picture
    10,796 User Group Leader on at

    I myself learnt about computed columns many years ago from this link daxmusings.codecrib.com/.../computed-view-columns-in-ax-2012.html and I confirm this is still valid - very well explained.

    I also documented my understanding here https://daxture.blogspot.com/2015/03/computed-columns-in-views-dynamics-ax.html

    However, read through MS docs article too to get initial understand and understand comparisons.

    docs.microsoft.com/.../data-entity-computed-columns-virtual-fields

  • Community Member Profile Picture
    on at

    Thank you all for your kind explanation.

    Much appreciated.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans