Count or Sum input values

Count or Sum input values

  

Hi,

In my WebApp I have a StudentDetails page with some data related with that student and have a preview (ExamsResults) with the information of the

exams that the student did and the results that she/he had in these exams.


ExamsResults Table:

- StudentId

- Date

- Result


I would like to display the following on the StudentDetails page at the bottom of the ExamsResults view table:

- Number of exams the student did (Count or Sum);

- Average student had on exams (Avg).


How can I do this?

Can anyone help me please?


Thanks in advance,

Clara


Hi Clara,

That should be easy enough using Aggregates. I assume your ExamsResults Entity has a single entry for each exam? In that case, use the following:

  1. Create an Aggregate from the ExamResults Entity (e.g. by dragging the Entity onto the canvas);
  2. Click the arrow that appears in the top right corner of the Result column header when you move the mouse over it, and select "Count". Rename the new Count column to something sensible (e.g. "ExamCount"):
  3. Repeat the process but this time select "Average". The result should be something like this:

Note that in case you want a count and an average per student (in the above I assume you filter the Aggregate for a single StudentId), you need to double click the blue "2" arrow to expose the StudentId, and click "Group by StudentId". This introduces another Attribute to the Aggregate, and ensures there's one ExamCount and ResultAvg per student (usefull for reports etc.).

Hi Kilian,

Thanks for your explantion and help.

At this moment I am not able to obtain in the "StudentsDetails" page the correct values of the sum and the average of the student.

What am I doing wrong?


I tried to create a web block, but the result was the same as the one in the attached file.

In the attached file version I just created a new "Aggregate" in the Preparation of the "StudentsDetails" page.


Thanks in advance,

Clara



Hi,

I made some changes and now I have the values of the count and average but have 2 issues:

- After insert "New Exams Result" on "StudentsDetails" page the count and average values not refresh;

- On average result how can I limit the value to only have two decimal places?


Thanks in advance,

Clara



Hi Clara,

You need to refresh aggregate and the part of page which holds these values.

Use these controls.

and use Round function to limit decimal to two places.

As for limiting the decimal to two places, you could either use Round to round the value (built-in function) or use FormatDecimal (also built-in function).

Hi,

First off all thanks Kilian and thanks Suraj.

Average result with round function works fine but the refresh... not working.

On the "StudentsDetails" page, where I have the aggregate for the count and average I created a new action "RefreshStudentsDetails" where I refresh the data and refresh the "StudentShow" but... maybe it is not the correct way.

Clara



Hi Clara,

Some observations:

  1. In GetExamsResultsByStudentId2 you have a group by StudentId, but since you also filter on a specific StudentId, this grouping does nothing (such grouping is only sensible when not filtering on a specific student, e.g. for reporting). Also, there's an additional grouping on Id, but that's equal to StudentId (because of the join condition), so it doesn't do anything either. So you should remove both groupings.
  2. The RefreshStudentDetails screen action is never called, as is evident by the brown squigly lines below it (mouse over or check the TrueChange to see "'RefreshStudentsDetails' action is never used in StudentsDetails"). So it makes sense nothing is ever refreshed :).



Hi Kilian,

Thanks again for your explantion but I'm confused about point 2.

Where can I call the RefreshStudentDetails screen action like you said?

Thanks for your support.

Regards,

Clara

Solution

Hi Clara,

It's a pitty you're confused :). However, you must understand that nothing "happens" to a web page unless you explicitly trigger it. This typically is a user clicking a button. If you create code but don't call it anywhere, it's not getting executed.

I would advise you to create a Refresh button on the screen, and call your RefreshStudentDetails action when it's pressed. That way you can see if the functionality works, before goind the advanced route with event systems or JavaScript call backs :).

Solution


Hi  Kilian,

Thanks for your answers and your support.

The "refresh" button works fine.

Regards,

Clara


Great to hear Clara! For book-keeping, could you mark my post above as Solution, so this thread will end up as Solved? Thanks!