How to count number of rows with multiple specific values in multiple column?

How to count number of rows with multiple specific values in multiple column?

langdeyouhuolangdeyouhuo Posts: 4Questions: 1Answers: 0

I want to retrieve the num of rows that having "value5" in column5. Also I want to use regular expression for the values.

I tried the following code, it does not work.

var row_count_agency = dt.column(':contains(column5)').rows(':contains("value5")').data().length;

This question has an accepted answers - jump to answer

Answers

  • langdeyouhuolangdeyouhuo Posts: 4Questions: 1Answers: 0

    I find out filter function, but I could not figure out how to filter column1 with value1 and column2 with value2?

    var row_count_agency = dt.column( 5 ).data().filter( function ( value, index ) { return value == "value1" ? true : false;} ).length

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Hi @langdeyouhuo ,

    You can use filter() for that - see here,

    Cheers,

    Colin

  • langdeyouhuolangdeyouhuo Posts: 4Questions: 1Answers: 0

    Thanks @Colin !

    But I want to filter with two conditons: column1 with value1 and column2 with value2.

    The example you showed to me is only filtering 1 column with specific value.

    Is it able to filter column1 with value and then filter column2 with value2, then I want to get the final result.

    Best Regards
    langdeyouhuo

  • colincolin Posts: 15,112Questions: 1Answers: 2,583
    Answer ✓

    Hi @langdeyouhuo ,

    Yep, you'll need to scan through the rows for that, something like this,

    Cheers,

    Colin

  • langdeyouhuolangdeyouhuo Posts: 4Questions: 1Answers: 0

    Thanks @colin !

This discussion has been closed.