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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Get a count of the rows which has specific value

KT_10107318
6-Contributor

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 

1 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

KT_10107318
6-Contributor
(To:DanZ)

I will try this too

Top Tags