Skip to main content
16-Pearl
April 17, 2024
Solved

How to get an output as float with 2 decimal values from valuestream without using for loop

  • April 17, 2024
  • 1 reply
  • 2259 views

How to get an output as float with 2 decimal values from valuestream without using for loop

- we tried using querynumberpropertyhistory to get an output as float values with2 decimal points with for loop. but for loop is creating an performance issues on server.

 

so tried to bind querynumberpropertyhistory service to line chart and tried to to achieve y axis values as float with 2 decimals but its not working on line chart. its working only on y axis labels not values.

 

can anyone knows how to achieve this?

 

Thanks!!!

Best answer by Arun_C

Hi @Suraj_Patil ,

 

Kindly refer the below given code FYR. 

let data = me.QueryNumberPropertyHistory({
	oldestFirst: false /* BOOLEAN */ ,
	maxItems: 9999999 /* NUMBER {"defaultValue":500} */ ,
	endDate: endTime /* DATETIME */ ,
	propertyName: PropertyInput /* STRING */ ,
	query: undefined /* QUERY */ ,
	startDate: startTime /* DATETIME */ ,
	quality: undefined /* STRING */
});
///***/// Dervie the data based on the expression ///****////
let params = {
	types: 'NUMBER' /* STRING */ ,
	t: data /* INFOTABLE */ ,
	columns: 'value' /* STRING */ ,
	expressions: 'value.toFixed(2)' /* STRING */
};
var derivedData = Resources["InfoTableFunctions"].DeriveFields(params);

///***/// Remove unwanted column or feild - id ///****////
derivedData.RemoveField('id');

///***/// Rename the infotable with actual feild values ///****////
var timestamp_Rename = renameFeildName(derivedData, 'timestamp', 'Timestamp');
var value_Rename = renameFeildName(timestamp_Rename, 'value', 'PropertyInput');
result = value_Rename;

///****/// Function to rename feildName without any loop ///***////
function renameFeildName(InfoTable, OldName, NewName) {
	let params = {
		t: InfoTable /* INFOTABLE */ ,
		from: OldName /* STRING */ ,
		to: NewName /* STRING */
	};
	return Resources["InfoTableFunctions"].RenameField(params);
}

It may helps in your case.

 

Thanks & Regards,

Arun C 

1 reply

16-Pearl
April 17, 2024

Hi @Suraj_Patil , Hope this snippet Dervie feild may helps you in this case.

 

let params = {
	types: 'NUMBER' /* STRING */,
	t: IP_Data /* INFOTABLE */,
	columns: 'Value' /* STRING */,
	expressions: 'Value.toFixed(2)' /* STRING */
};

// result: INFOTABLE
let result = Resources["InfoTableFunctions"].DeriveFields(params);

 Note: Rename 'Value' columnname based on your property name.

 

Thanks & Regards,

Arun C

16-Pearl
April 18, 2024

it will work actually but i need to use for loop again to get updated info table with separate data shape. i want to avaoid for loop anyhow . can anyone help in this

16-Pearl
April 20, 2024

Hi @Suraj_Patil ,

 

Can you please paste the piece of your code and let us know what exactly you looking for our better understand.

 

Thanks & Regards,

Arun C