def _factors_count(idadf, columnlist, valuelist=None):
    """
    Count non-missing values for all columns in a list (valuelist) over the
    IdaDataFrame grouped by a list of columns(columnlist).

    Parameters
    ----------
    columnlist : list
        List of column names that exist in self.
    valuelist : list
        List of column names that exist in self.

     Notes
     -----
     The function assumes the following:

        * The columns given as parameter exists in the IdaDataframe
        * The parameter columnlist is a optional and is a list
        * Columns are referenced by their own name (character string)

    Returns
    -------
        DataFrame
    """
    column_string = '"' + '", "'.join(columnlist) + '"'
    name = idadf.internal_state.current_state
    if valuelist is None:
        query = (
            'SELECT %s, COUNT(*) as COUNT FROM %s GROUP BY %s ORDER BY %s, COUNT ASC'
             % (column_string, name, column_string, column_string))
    else:
        agg_list = []
        for value in valuelist:
            query = 'COUNT("%s") as "%s"' % (value, value)
            agg_list.append(query)
        agg_string = ', '.join(agg_list)
        value_string = '"' + '", "'.join(valuelist) + '"'
        query = 'SELECT %s,%s FROM %s GROUP BY %s ORDER BY %s,%s ASC' % (
            column_string, agg_string, name, column_string, column_string,
            value_string)
    return idadf.ida_query(query)
