Jump to content
  • 0

Converting virtual fields to numeric values for use in calcualtions



I have a datapage that utilizes virtual fields to collect user input values that I don't want to store in tables, but do want to use for some generally simple calculations.  However, because virtual fields don't store the input as numeric, I keep getting calculation errors.  Here is a simple example of one calculation that I can't get to work:


VirtualField1 is a text box

VirtualField2 is a dropdown with the options "in" and "mm"

VirtualField3 is a calculated field with the following formula:


WHEN [@cbParamVirtual2] = 'mm' THEN [@cbParamVirtual1]/25.4

ELSE [@cbParamVirtual1]



No matter what tweaks I have tried, I either get a "calculation error" message or just nothing appears in the VirtualField3.  Any suggestions would be greatly appreciated.  Thanks!

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 1

Hi @CMorris,

Values from virtual fields do not have a datatype.

You would need to wrap the fields reference with single quotes to make them string type and convert the string to float type.

You can use T-SQL function CAST or CONVERT for this.

So, your expression will look like this:


WHEN '[@cbParamVirtual2]' = 'mm' THEN CAST('[@cbParamVirtual1]' AS FLOAT)/25.4

ELSE CAST('[@cbParamVirtual1]' AS FLOAT)




Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...