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

How to convert datatable's data into Number

SOLVED
Alexandrite

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

Re: How to convert datatable's data into Number

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
Highlighted

Re: How to convert datatable's data into Number

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

Re: How to convert datatable's data into Number

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

Re: How to convert datatable's data into Number

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

 

Re: How to convert datatable's data into Number

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

Re: How to convert datatable's data into Number

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

Re: How to convert datatable's data into Number

Hi slangley

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

 

Re: How to convert datatable's data into Number

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

Re: How to convert datatable's data into Number

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

Re: How to convert datatable's data into Number

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