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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

total count of number of values in a column from infotable

achitters
9-Granite

total count of number of values in a column from infotable

We have a service for how to get a row count. In the same way can we get the number of values (type is String) of the specified column or all the columns from the infotable as the input to the service.

Thanks 

achitters

1 ACCEPTED SOLUTION

Accepted Solutions

Hello,

 

Is that what you're looking for?

 

// Some test data
var input = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({ dataShapeName: "NamedVTQ" });
input.AddRow({ name: 'a', quality: '1' });
input.AddRow({ name: 'b', quality: '2' });
input.AddRow({ name: 'a', quality: '3' });
input.AddRow({ name: 'b', quality: '4' });
input.AddRow({ name: 'a', quality: '5' });
var columnName = 'name';

// Count unique values
var result = Resources["InfoTableFunctions"].Aggregate({
	t: input,
	columns: columnName,
	aggregates: 'COUNT',
	groupByColumns: columnName
}).rows.length;	// Should return 2 ("a" and "b")

 

/ Constantine

View solution in original post

2 REPLIES 2
slangley
23-Emerald II
(To:achitters)

Hi @achitters.

 

We're not totally clear on what you are asking.  Are you concerned about nulls in some of the fields?  If so, there is a snippet called InfoTable For Loop that can read each row and perform whatever logic needed, then continue through the table until it reaches the end.

 

Please let us know if this does not answer your question.

 

Regards.

 

--Sharon

 

 

Hello,

 

Is that what you're looking for?

 

// Some test data
var input = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({ dataShapeName: "NamedVTQ" });
input.AddRow({ name: 'a', quality: '1' });
input.AddRow({ name: 'b', quality: '2' });
input.AddRow({ name: 'a', quality: '3' });
input.AddRow({ name: 'b', quality: '4' });
input.AddRow({ name: 'a', quality: '5' });
var columnName = 'name';

// Count unique values
var result = Resources["InfoTableFunctions"].Aggregate({
	t: input,
	columns: columnName,
	aggregates: 'COUNT',
	groupByColumns: columnName
}).rows.length;	// Should return 2 ("a" and "b")

 

/ Constantine

Top Tags