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

total count of number of values in a column from infotable

SOLVED
Highlighted
Gravel

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

Tags (3)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: total count of number of values in a column from infotable

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
Highlighted

Re: total count of number of values in a column from infotable

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

 

 

Highlighted

Re: total count of number of values in a column from infotable

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

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum!