cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

How to convert datatable's data into Number

xiaoqw
15-Moonstone

How to convert datatable's data into Number

As I want to retrieve data from datatable and do calculation with number, how to convert data in the datatable

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @xiaoqw ,

 

RenameField returns an INFOTABLE and not an INTEGER, so you probably want to do something like this:

 

 

var result = parseInt(output.value);
// or
var result = parseInt(output.rows[0].value);

 

 

/ Constantine 

View solution in original post

9 REPLIES 9
slangley
23-Emerald II
(To:xiaoqw)

Hi @xiaoqw.

 

Are you trying to convert existing data in the table?  We tested using a string value and were able to perform calculations on it without the need to convert the data type. If your scenario is different you could try running the parseInt() function.

 

If you still have issues, please provide specifics of your datatable so we can test further.

 

Regards.

 

--Sharon

xiaoqw
15-Moonstone
(To:slangley)

var output = Resources["InfoTableFunctions"].RenameField({
t: Resources["InfoTableFunctions"].Aggregate({
t: me.QueryDataTableEntries({ maxItems: undefined,
query: query,
values:undefined,
source: undefined,
tags:undefined
}),
columns: 'value',
aggregates: 'SUM',
groupByColumns: 'value'
}),
from: "SUM_value",
to: "value"
});

var result = parseInt(output);

 here is my code and output should be number but now is NaN. Please take a look and give me suggestion how to edit

Hello @xiaoqw ,

 

RenameField returns an INFOTABLE and not an INTEGER, so you probably want to do something like this:

 

 

var result = parseInt(output.value);
// or
var result = parseInt(output.rows[0].value);

 

 

/ Constantine 

slangley
23-Emerald II
(To:slangley)

Hi @xiaoqw.

 

The query has not been defined, so we're not clear on what you are trying to do.  It also looks like you're attempting to rename a field.  Is this your intent?

 

We can't tell what kind of data you have in your datatable from the sample code you provided, so need more information to be able to assist.

 

Regards.

 

--Sharon

 

xiaoqw
15-Moonstone
(To:slangley)

hello slangley,

 I need to do SUM aggregation function first and get the sum value. 

after that, I will use SUM value to do a calculation. so how should I put formula on this service.

image1.pngimage3.png

xiaoqw
15-Moonstone
(To:slangley)

And my query is filter function. to filter data from datatable.

xiaoqw
15-Moonstone
(To:slangley)

Hi slangley

I have attached my recent code in community. Could u help me to figure it out?

 

xiaoqw
15-Moonstone
(To:slangley)

Hi @slangley ,

 

 I need to do SUM aggregation function first and get the sum value. 

after that, I will use SUM value to do a calculation. so how should I put formula on this service.

image1.pngimage3.png

slangley
23-Emerald II
(To:xiaoqw)

Hi @xiaoqw.

 

Can you either copy the full code for the service, or export the thing containing the service so we can see better what you are trying to do?

 

Regards.

 

--Sharon

Top Tags