Skip to main content
8-Gravel
October 10, 2022
Solved

Get a count of the rows which has specific value

  • October 10, 2022
  • 2 replies
  • 1769 views

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 

Best answer by Sathishkumar_C

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);​

2 replies

17-Peridot
October 11, 2022

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);​
8-Gravel
October 11, 2022

Thanks it works 

15-Moonstone
October 11, 2022

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

8-Gravel
October 11, 2022

I will try this too