To add on to what Robert is saying, you could take this solution a step further and define the aggregate within the expression, instead of doing it at the FIELD tab. So it would look like this:
I strongly recommend doing it this way, instead of defining aggregates in the FIELD tab. This is because it can get real buggy if you try to use that same field for any criteria in the query later on. It's pretty insidious too, since the only way to really know why the error is happening is to look at the SQL!
The example below shows what is happens when this error occurs:
You could say that the PSQuery just isn't having it, when this error occurs... but then your friend will groan and call you a nerd...
On flip-side, if you were to do the same thing, but instead define the aggregate within the expression (And NOT add the aggregate in the FIELDS tab), PSQuery will be smart enough to write the correct SQL statement and put your aggregated field nicely into the HAVING clause, and no error should be thrown.
Ultimately, understanding what the heck is going on when working with aggregates is hard, and when PSQuery starts writing the underlying SQL in unexpected ways, it just makes it that much harder.
Hoping this helps!
Jeffrie
On Tue, Feb 25, 2025 at 7:34β―AM Robert Fogarty via Higher Education User Group <
Mail@heug.org> wrote:
This field is an aggregate field but is being used in non-having criteria error happens when the field being used in the sub query aggregate is... -posted to the "PS Query & SQL" group
| Re: Minimum Plan Sequence | | | | | | This field is an aggregate field but is being used in non-having criteria error happens when the field being used in the sub query aggregate is being used in the criteria tab.
The work around is to create the field as an expression,  then use the expression as as field from the Expressions Tab then apply your aggregation ... you will notice that there is no description now from the Record.Fieldname because it is an expression
------------------------------ Robert Fogarty PMP Reporting Team Lead | LionPATH Development and Maintenance Office The Pennsylvania State University ------------------------------
Message from the HEUG Marketplace: ------------------------------ Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the HEUG Marketplace. ------------------------------ | | | Reply to Community Reply to Sender via Email View Thread Recommend |
Original Message: Sent: 02-24-2025 01:12 PM | |
| |
-- Jeffrie Brooks | BUSINESS SYSTEM ANALYST UNIVERSITY OF MICHIGAN | INFORMATION AND TECHNOLOGY SERVICES | |
Original Message:
Sent: 2/25/2025 7:34:00 AM
From: Robert Fogarty
Subject: RE: Minimum Plan Sequence
------------------------------
Robert Fogarty PMP
Reporting Team Lead | LionPATH Development and Maintenance Office
The Pennsylvania State University
------------------------------
Message from the HEUG Marketplace:------------------------------
Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the
HEUG Marketplace.
------------------------------
Original Message:
Sent: 02-24-2025 01:12 PM
From: Rachael Daniel
Subject: Minimum Plan Sequence
And every time I try to set that to MIN, I get this. So I'm sure I'm missing something in how I build that out.

Rachael Daniel
Director, Systems & Data Analysis
Division of Strategic Enrollment Management & Student Success
University of Wisconsin-Milwaukee
414-229-4277
rdaniel@uwm.edu
My pronouns are she/her/hers
Original Message:
Sent: 2/24/2025 1:01:00 PM
From: Daniel Labrecque
Subject: RE: Minimum Plan Sequence
I think what you are wanting to use is a subquery on PLAN_SEQUENCE. In the subquery you will do your joins as usual, but will select the PLAN_SEQUENCE field and make that minimum.

------------------------------
Daniel Labrecque
Senior 2 Business Systems Analyst/Functional Architect
University of Nevada, Las Vegas
------------------------------
Message from the HEUG Marketplace:------------------------------
Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the
HEUG Marketplace.
Original Message:
Sent: 02-24-2025 12:50 PM
From: Rachael Daniel
Subject: Minimum Plan Sequence
Sorry, I should have been more clear. If a student has more than one plan, I want the one where, for this single career number, the PLAN_SEQUENCE is the minimum sequence. The dates there (for declare date or eff date) don't always equate the minimum plan sequence number. For example, I want to return ONLY the ACCBBA2 plan code, because it's the minimum sequence number.

Rachael Daniel
Director, Systems & Data Analysis
Division of Strategic Enrollment Management & Student Success
University of Wisconsin-Milwaukee
414-229-4277
rdaniel@uwm.edu
My pronouns are she/her/hers
Original Message:
Sent: 2/24/2025 12:43:00 PM
From: Daniel Labrecque
Subject: RE: Minimum Plan Sequence
Hello Rachel,
I think you can change the EFFDT criteria to:

By default it is set to Current Date (EffSeq = Last).
------------------------------
Daniel Labrecque
Senior 2 Business Systems Analyst/Functional Architect
University of Nevada, Las Vegas
------------------------------
Message from the HEUG Marketplace:------------------------------
Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the
HEUG Marketplace.
Original Message:
Sent: 02-24-2025 11:20 AM
From: Rachael Daniel
Subject: Minimum Plan Sequence
Hello β
I'm not sure what I'm missing here, or if I am just having a bad day π. Can anyone share how to only return a plan from the ACAD_PLAN table on a student record that has the minimum sequence value? Thanks in advance!
Rachael Daniel
Director, Systems & Data Analysis
Division of Strategic Enrollment Management & Student Success
University of Wisconsin-Milwaukee
414-229-4277
rdaniel@uwm.edu
My pronouns are she/her/hers