Pull Top Three Entries in a Data Set

An Major shared this question 7 months ago
Answered

Is there a way I can pull the last entry and/or last three entries of a data set using a calculated field?

Comments (3)

photo
1

Hi An,

Thanks for reaching out. You can get the last result of a data set by using the MAX function, like so:

/CtgiYXi4iLnx7+1pGZ+EfDFnD5+waAeCCCAAAIIIIAAAggggAACCCCAQFAESPoEJZK0AwEEEEAAAQQQQAABBBBAAAEEEPAIkPTxYLCKAAIIIIAAAggggAACCCCAAAIIBEWApE9QIkk7EEAAAQQQQAABBBBAAAEEEEAAAY8ASR8PBqsIIIAAAggggAACCCCAAAIIIIBAUARI+gQlkrQDAQQQQAABBBBAAAEEEEAAAQQQ8AiQ9PFgsIoAAggggAACCCCAAAIIIIAAAggERYCkT1AiSTsQQAABBBBAAAEEEEAAAQQQQAABjwBJHw8GqwgggAACCCCAAAIIIIAAAggggEBQBEj6BCWStAMBBBBAAAEEEEAAAQQQQAABBBDwCJD08WCwigACCCCAAAIIIIAAAggggAACCARFgKRPUCJJOxBAAAEEEEAAAQQQQAABBBBAAAGPAEkfDwarCCCAAAIIIIAAAggggAACCCCAQFAESPoEJZK0AwEEEEAAAQQQQAABBBBAAAEEEPAIkPTxYLCKAAIIIIAAAggggAACCCCAAAIIBEWApE9QIkk7EEAAAQQQQAABBBBAAAEEEEAAAY8ASR8PBqsIIIAAAggggAACCCCAAAIIIIBAUARI+gQlkrQDAQQQQAABBBBAAAEEEEAAAQQQ8AiQ9PFgsIoAAggggAACCCCAAAIIIIAAAggERYCkT1AiSTsQQAABBBBAAAEEEEAAAQQQQAABj0Do9OnTnl9ZRQABBBBAAAEEEEAAAQQQQAABBBAIgkBo2bJlQWgHbUAAAQQQQAABBBBAAAEEEEAAAQQQ8Ahwe5cHg1UEEEAAAQQQQAABBBBAAAEEEEAgKAIkfYISSdqBAAIIIIAAAggggAACCCCAAAIIeARI+ngwWEUAAQQQQAABBBBAAAEEEEAAAQSCIkDSJyiRpB0IIIAAAggggAACCCCAAAIIIICAR4CkjweDVQQQQAABBBBAAAEEEEAAAQQQQCAoAiR9ghJJ2oEAAggggAACCCCAAAIIIIAAAgh4BEj6eDBYRQABBBBAAAEEEEAAAQQQQAABBIIiQNInKJGkHQgggAACCCCAAAIIIIAAAggggIBH4P8DFpC+RxPcbdgAAAAASUVORK5CYII=

/AbVuDcYEMBaQAAAAAElFTkSuQmCC

You can also use MIN for the first entry, which in my case is a NULL value:

/x1Ik7IIlKmqAAAAAElFTkSuQmCC

This is all in isolation though. Depending on what else you pull in it may be difficult to get the results you'd be looking for.

In standard SQL you can use things like LIMIT in MySQL, TOP in SQL Server, and ROWNUM in Oracle, but these are not supported using Freehand SQL:

/gRNyIbd1d59X416kJ5EgEicNMR4CIYc6ZgeKEJymWYlL3peFCBiQARIAISBEhZlQBDwUSACBABIkAEiAARIAJEgAgQASKwegRoz+rqsaeciQARIAJEgAgQASJABIgAESACRECCACmrEmAomAgQASJABIgAESACRIAIEAEiQARWjwApq6vHnnImAkSACBABIkAEiAARIAJEgAgQAQkCpKxKgKFgIkAEiAARIAJEgAgQASJABIgAEVg9AqSsrh57ypkIEAEiQASIABEgAkSACBABIkAEJAiQsioBhoKJABEgAkSACBABIkAEiAARIAJEYPUIkLK6euwpZyJABIgAESACRIAIEAEiQASIABGQIEDKqgQYCiYCRIAIEAEiQASIABEgAkSACBCB1SNAyurqsaeciQARIAJEgAgQASJABIgAESACRECCACmrEmAomAgQASJABIgAESACRIAIEAEiQARWjwApq6vHnnImAkSACBABIkAEiAARIAJEgAgQAQkCpKxKgKFgIkAEiAARIAJEgAgQASJABIgAEVg9AqSsrh57ypkIEAEiQASIABEgAkSACBABIkAEJAiQsioBhoKJABEgAkSACBABIkAEiAARIAJEYPUIkLK6euwpZyJABIgAESACRIAIEAEiQASIABGQIEDKqgQYCiYCRIAIEAEiQASIABEgAkSACBCB1SNAyurqsaeciQARIAJEgAgQASJABIgAESACRECCACmrEmAomAgQASJABIgAESACRIAIEAEiQARWjwApq6vHnnImAkSACBABIkAEiAARIAJEgAgQAQkCpKxKgKFgIkAEiAARIAJEgAgQASJABIgAEVg9AqSsrh57ypkIEAEiQASIABEgAkSACBABIkAEJAiQsioBhoKJABEgAkSACBABIkAEiAARIAJEYPUIkLK6euwpZyJABIgAESACRIAIEAEiQASIABGQIEDKqgQYCiYCRIAIEAEiQASIABEgAkSACBCB1SNAyurqsaeciQARIAJEgAgQASJABIgAESACRPS46mUAAAAJSURBVECCwP8Hu0K+OWhrQ68AAAAASUVORK5CYII=

There are of course ways to manually obtain this information - for example, sorting the field in question in descending order, then bringing in a filter for said field and manually choosing those 3 values in a list. This is of course not dynamic so it would only be good for static reports. If you want to display 3 most recent data entries, but not just the 3 most recent data entries you can just leave the field in the report sorted as descending, so each time it's reloaded the last entry is on top of the report.

Ultimately, I'm afraid data-specific SQL solutions are a bit outside the scope of Support, so I'm afraid there's not much else I can add here, but please let me know if you have any further questions on anything I've mentioned thus far.

Regards,

Mike

photo
1

Hi An,

I just wanted to check in and see how things are going with this.

Regards,

Mike

photo
1

Hi An,

I'm going to go ahead and mark this one as Answered since I haven't heard back from you, but if you have further questions or concerns on this, if you respond, it will re-open the case and put it back in my queue and I'll be happy to help.

Regards,

Mike