You are viewing limited content. For full access, please sign in.

Discussion

Discussion

CountIF

posted on August 26, 2016 Show version history

Trying to use the COUNTIF function in a Form to check how many times a value appears in a series of Radio Buttons. My series of Buttons have 3 choices, Acceptable, Not Acceptable and N/A and have values assigned, 1,0,NA.

My Formula looks like =COUNTIF(Fieldname1,FieldName2,Fieldname3,"=NA") but it returns nothing regardless of the settings of the Radio button.

I've even tried the sample shown in the Help =COUNTIF(1,2,3,"a","b","c",">1") the result should be 2, but this does nothing as well. 

Has anybody else tried the COUNTIF function in Forms and had it work?

0 0
replied on August 28, 2016

It's true that COUNTIF function takes exactly 2 arguments. But for the first parameter, it could be either variable of an array, or just an array like '[1,2,3,"a","b","c"]'. So it should be '=COUNTIF([1,2,3,"a","b","c"],">1")'

2 0
replied on August 28, 2016

How did I not check with brackets? Checked with parentheses and curly braces...no brackets...that's my bad.

0 0
replied on August 26, 2016 Show version history

UPDATE: Refer to Rui's comment.

General Commentary

You seem to be absolutely right, the example in the Help Files seems to have never worked.

The COUNTIF function per the OpenFormula standard takes exactly 2 arguments: the first is a range of values (say, spreadsheet cells), and the second is the condition. If you use the Forms analogues of the "range of values" and specify a field within a collection (CollectionName.FieldName) or a column within a table (TableName.ColumnName), this will work as expected.

In fact, if you try to enter the example as an actual field calculation, upon page refresh there is actually a calculation error on the field, for an invalid number of arguments. This is because the specs really call for only two arguments, not an indefinite amount. If you try to use the COUNTIF function in Microsoft Excel or Google Sheets, you will have the same issue.

I will follow up with the Forms team whether the example in the Help Files should be changed, or whether the behavior of the COUNTIF function within Laserfiche Forms can be modified to reflect the example, as that seems like a useful implementation.

For Your Particular Needs

In this demonstration we have a fixed number of three radio button sets in a collection named coll. Each radio button set is named radio. The Single Line field has the following formula:

=COUNTIF(coll.radio,">1")

The individualized labels for the radio button sets, by the way, are handled by this custom JavaScript:

$(document).ready(function() {
  $('.coll .cf-collection div.form-q').each(function(index,element) {
    switch(index) {
      case 0:
        $(element).find('.rad .cf-label').html('Label for the first set');
        break;
      case 1:
        $(element).find('.rad .cf-label').html('Second set label');
        break;
      case 2:
        $(element).find('.rad .cf-label').html('This one is III');
        break;
    }
  });
});

(The collection item in the Forms editor is given the "coll" CSS class and the radio button set in the collection is given the "rad" CSS class.)

Hope this helps!

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.