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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Get a count of the rows which has specific value

KT_10107318
7-Bedrock

Get a count of the rows which has specific value

Hi all, i have a infotable which is returned from Store procedure. The infotable has a column which returns 0 and 1. Is there any way to get the count of the rows which has value 1. Thanks in advance 

ACCEPTED SOLUTION

Accepted Solutions

I think of 2 ways...

  • The 1st one with do the query on infotable with 0 or 1 and get a row count.
var query = {
   "filters":{
      "type": "EQ",
      "fieldName": "<field_name>",
      "value": 1
   }
}; 
let params = {
	t: <infotable data>/* INFOTABLE */,
	query: query /* QUERY */
};
// result: INFOTABLE
let result = Resources["InfoTableFunctions"].Query(params);
  • The 2nd one do aggregate function with group by columns
    let params = {
    	t: <infotable data>/* INFOTABLE */,
    	columns: <any unique field> /* STRING */,
    	aggregates: 'COUNT'/* STRING */,
    	groupByColumns: <0 or 1 field> /* STRING */
    };
    // result: INFOTABLE
    let result = Resources["InfoTableFunctions"].Aggregate(params);​

View solution in original post

4 REPLIES 4

I think of 2 ways...

  • The 1st one with do the query on infotable with 0 or 1 and get a row count.
var query = {
   "filters":{
      "type": "EQ",
      "fieldName": "<field_name>",
      "value": 1
   }
}; 
let params = {
	t: <infotable data>/* INFOTABLE */,
	query: query /* QUERY */
};
// result: INFOTABLE
let result = Resources["InfoTableFunctions"].Query(params);
  • The 2nd one do aggregate function with group by columns
    let params = {
    	t: <infotable data>/* INFOTABLE */,
    	columns: <any unique field> /* STRING */,
    	aggregates: 'COUNT'/* STRING */,
    	groupByColumns: <0 or 1 field> /* STRING */
    };
    // result: INFOTABLE
    let result = Resources["InfoTableFunctions"].Aggregate(params);​

Thanks it works 

DanZ
15-Moonstone
(To:KT_10107318)

The approach of Sathishkumar_C is totally fine. But as a short alternative the following is also possible:

 

const result = infotable.rows.toArray().filter(row => row.valueColumn === 1).length;

 

infotable --> your infotable variable

valueColumn --> your column name with the value

I will try this too

Announcements


Top Tags