Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Need to count cells >0 from multiple tables and display Total Count

Avatar

Level 1

I created a performance evaluation form that has multiple tables (6) (all have two columns with the last row/column of each table a total of possible points for that section).

At the end of the form I want to be able to count all the 2nd columns (not the totals)  that are >0 and display that number.

Any help would be greatly appreciated.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Simply do a verification that values are greater than 0 each..

View solution in original post

9 Replies

Avatar

Level 7

You will need to use a global variable to count the items that meet your 'if' logic and then display it in a textfield.

Avatar

Level 1

I'm sorry.  I am quite the novice with LC.  Can you give me more info or an example of an if statement that counts?

Avatar

Level 10

Hi,

You can get a count of number of cells with a value greater than zero with an expression like;

Table1.resolveNodes("Row1.[NumericField1 > 0]").length

This assumes the second column is called NumericField1, and the table is called Table1 and the row called Row1 ... so you will probably have to change those.

You could have six expressions like this one in the calculate event of the you total field and add them together.

Regards

Bruce

Avatar

Level 1

Bruce,

I'm sure that would work but I couldn't get it to with my limited knowledge.  However after poking around, I did get an if statement to calculate each table for me and then I used sum to add each to get to my total count.  Probably the long way around but it works.  Here's my next question if you can help.

I want to take the sum (Raw) and divide by the  Count (Avail) to get a Score.  I thought that was pretty simple but I get the following error using this.   - but it still gives me the correct answer. I would like to get rid of this error box.  Any help would be great.

form1.Subform9.Table7.Row4.Score::calculate - (FormCalc, client)

Score = Row2.Raw / Row3.Avail

1359533_pastedImage_2.png

Avatar

Level 1

I forgot to add that the Raw and Avail cells are calculated if that makes a difference.  Thanks.

Avatar

Level 10

Hi there,

it seems like one of those value are equal to 0.

You cannot divide a value by 0, so unless you make an if statement to make sure none of these values are equal to 0 you might get that message often.

Hope this help!

Avatar

Level 1

I tried the following but maybe I'm missing something. (both fields could be blank at some point until the user starts filling in the blanks.

I googled this to get rid of my zero division  and I do get the calculation but I want to get rid of the error message.

Do I need another if statement? and how would I do that?

if(HasValue(Row2.RawCount&Row2.RawCount>0)) then (Row2.RawCount/Row3.Avail) else null endif

Avatar

Correct answer by
Level 10

Simply do a verification that values are greater than 0 each..

Avatar

Level 1

That worked!  I have been struggling with this form for days...  Thank you so much!