I've also used windowing functions to "flatten" results in a manner similar to the one described here, and I thought it might be useful for folks unfamiliar with this technique to know that the "Distinct" box should be checked in the query properties (or however the user would add the DISTINCT keyword to the Select statement at the top level of the query), since the windowing functions themselves aren't actually flattening anything; rather, they're just generating a constant value (the one corresponding to the row sought after within the window) in the field created by the expression.
For example, you'd initially get something like the following table for the first two IDs, assuming for illustrative purposes only 3 values for TREE_NODE ('GENERALFEES', 'TECHNOLOGY', and 'OTHER')-these values make up the "window" of the windowing function (i.e., the group of rows, or partitions, defined by the field specified in the PARTITION BY clause, which in this case is EMPLID):
EMPLID GENERAL_FEES TECHNOLOGY OTHER
0000001 $159.00 $224.12 $22.37
0000001 $159.00 $224.12 $22.37
0000001 $159.00 $224.12 $22.37
0000002 $115.00 $126.70 $72.50
0000002 $115.00 $126.70 $72.50
0000002 $115.00 $126.70 $72.50
Applying the DISTINCT keyword would then deduplicate the table by all fields, resulting in the following, flattened/unpivoted/widened version of the above:
EMPLID GENERAL_FEES TECHNOLOGY OTHER
0000001 $159.00 $224.12 $22.37
0000002 $115.00 $126.70 $72.50
It's important to note, however, that any other fields excluded from the Select statement but that exist in the records used in the query and that vary on the partitioning field may contribute to the size of the window, therefore requiring a more complex windowing function to achieve the desired result with an ordered windowing function (e.g., NTH_VALUE), typically by adding said field or fields to the PARTITION BY clause as applicable to cycle through unique values; the ORDER BY clause is important here.
------------------------------
Robert Lang
Research Analyst
Duke 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: 11-12-2025 11:59 AM
From: Kendall Vance
Subject: What's your favorite expression, case statement, trick?
I find this manual unpivot trick comes in handy. If we have a field (e.g. "TREE_NODE" that contains values like 'GENERALFEES' , 'TECHNOLOGY' , etc, and our user wants those amounts broken out in separate columns, with one row per emplid:
expr1:
SUM(
CASE WHEN A.TREE_NODE = 'GENERALFEES' THEN A.TP_AMT ELSE 0 END
) OVER (PARTITION BY A.EMPLID) AS GENERAL_FEES
expr2:
SUM(
CASE WHEN A.TREE_NODE = 'TECHNOLOGY' THEN A.TP_AMT ELSE 0 END
) OVER (PARTITION BY A.EMPLID) AS TECHNOLOGY AS TECHNOLOGY
etc. etc.
Note: since this method uses window functions, don't check "Aggregate Function" in the Expression Properties or Query Manager will get angry.
Kendall Vance
IT Technical Associate for Financial Aid Reporting
Northern Illinois Univ
------------------------------
Kendall Vance
IT Technical Associate for Financial Aid Reporting
Northern Illinois University
------------------------------
Message from the HEUG Marketplace:
------------------------------
Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the HEUG Marketplace.
------------------------------