Skip to main content
1-Visitor
March 3, 2020
Solved

total count of number of values in a column from infotable

  • March 3, 2020
  • 2 replies
  • 2241 views

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

Best answer by Constantine

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

2 replies

Support
March 3, 2020

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

 

 

18-Opal
March 4, 2020

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