Jump to content
Server Maintenance This Week. ×

Sum top 3 rows in a portal


This topic is 4294 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Greetings,

I've got a portal row which displays the time for runners in each row. Outside the portal, I have a field which calculates the Sum time of all the runners within the portal.

What I have been trying to accomplish now is to have another field which makes a Sum of the top 3 times within the portal.

Let's say we have 4 runners with:

Runner 1 - 1 minute

Runner 2 - 4 minutes

Runner 3 - 1 minute

Runner 4 - 1 minute

Top 3 times sum: 3 minutes

Does anyone know how to achieve this?

Thanks

Link to comment
Share on other sites

Do you need this only for display, or is this going to be used in further calculations?

Thanks for the reply, it was only to display and then to be used for sorting in a printing view.

I have been able to get it done with GetLayoutObjectAttribute ( "ObjectName" ; "Content" ; 1 ; n ) which so far seems to be working beautifully, although a solution which doesn't require being in the layout would be even better in case I need to do calculations on it in the future.

Link to comment
Share on other sites

it was only to display and then to be used for sorting in a printing view.

Well, if it's to be used for sorting, then it's not "only to display".

If you sort your relationship by Time, descending ascending, you can then sum up the three best results as =

GetNthRecord ( Results::Time ; 1 ) +

GetNthRecord ( Results::Time ; 2 ) +

GetNthRecord ( Results::Time ; 3 )

Edited by comment
Link to comment
Share on other sites

Well, if it's to be used for sorting, then it's not "only to display".

If you sort your relationship by Time, descending, you can then sum up the three best results as =

GetNthRecord ( Results::Time ; 1 ) +

GetNthRecord ( Results::Time ; 2 ) +

GetNthRecord ( Results::Time ; 3 )

Sorry, didn't consider sorting as a calculation, my mistake.

Tried that option, but for some reason it would only sort by creation date and spent quite some time trying to get it to work that way, but upon reading the documentation it explained it could only do it that way and I gave up that method.

Edit: Thinking about it, maybe I was sorting incorrectly? I tried sorting both the current table and the related table, is there another way to sort a relationship through the relationships window or something like that?

Link to comment
Share on other sites

If you sort your relationship by Time, descending, you can then sum up the three best results as =

GetNthRecord ( Results::Time ; 1 ) +

GetNthRecord ( Results::Time ; 2 ) +

GetNthRecord ( Results::Time ; 3 )

Shouldn't it be ascending, since greater time = worse result?

Link to comment
Share on other sites

Sorry, didn't consider sorting as a calculation, my mistake.

Well, it's not exactly a calculation either. I guess the mistake was mine for not allowing a wider margin for "things that are not display".

Tried that option, but for some reason it would only sort by creation date

Not sure what you mean by that: you need to set the sort order of the result records in the definition of the relationship.

Shouldn't it be ascending, since greater time = worse result?

Right. Thanks for the catch.

Link to comment
Share on other sites

Not sure what you mean by that: you need to set the sort order of the result records in the definition of the relationship.

Had never used this part when defining a relationship, had to look around for it but this works great now, thanks for the help!

Link to comment
Share on other sites

This topic is 4294 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.