Skip to main content
1-Visitor
September 23, 2019
Solved

convert data into number in datatable

  • September 23, 2019
  • 2 replies
  • 2006 views

here is my coding which I want to do calculation using datatable data. output should be "NUMBER". but now result is NaN. Could someone help me figure it out?

 

var query =
{
"filters": {
"type": "And",
"filters": [
{
"type": "EQ",
"fieldName": "Department",
"value": "Milk"
},
{
"type": "EQ",
"fieldName": "Kategory",
"value": "Production Volume"
}
]
}
};

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/10000);

 

 

Best answer by PaiChung

 

var result = parseInt(output/10000);

It looks like you are trying to divide the whole infotable? maybe

var result = parseInt(output.value/10000);

 BTW it seems redundant to rename the field, not sure if you are trying to use the infotable somewhere else as well.

2 replies

PaiChung22-Sapphire IAnswer
22-Sapphire I
September 23, 2019

 

var result = parseInt(output/10000);

It looks like you are trying to divide the whole infotable? maybe

var result = parseInt(output.value/10000);

 BTW it seems redundant to rename the field, not sure if you are trying to use the infotable somewhere else as well.

xiaoqw1-VisitorAuthor
1-Visitor
September 24, 2019

Thank you for your help. it works!!!

16-Pearl
September 23, 2019

Hello Tracy,

 

Thank you for reaching out on the ThingWorx Developers Community.

 

I did some quick testing with the code provided and I believe you can achieve the desired results by changing the last line to the following:

var result = parseInt(output.value/10000);

 

When you call for output only the return is an Infotable. If you call for output.value you specifically get the single number from the value field.

 

Please let me know if this is helpful.

 

Regards,

Tyler Misner

ThingWorx Technical Support Engineer

16-Pearl
September 23, 2019

Looks like @PaiChung has already replied on this one.