The Basics of Expressions

  • An expression is some form of operation involving numbers, character strings, or dates and times.
  • Expressions can be used in a field or criteria.
  • Many SQL functions can be used in PS Query expressions.
  • You cannot use some SQL functions, such as 'if' or 'where' in Expressions.
  • Sometimes Expressions need tweaking.

Step by Step for Creating Expressions

  1. Expression is created in the "Expression" page. Click the "Add Expression" button to create a new expression

    expression tab
  2. Select Expression Type
  3. Set the length of the new field
  4. Type your expression in the box for "Expression Text."



  5. After creating an expression, click "Use as Field" if you want the new field to be used in the query.

    If you want to use the expression as a criteria, click the funnel icon. The criteria will be added to the Having tab if the field is an aggregated field. Please see the Having page for more information. Otherwise, the criteria will be under Criteria tab.



Back to top

Expression Examples:

Aggregate Function (AVG, COUNT, MAX, MIN, &SUM)

You will need to check the "Aggregate Function" box in your expression when you use aggregate function.

aggregate function

Examples:

FunctionUsageExample
AVGaverage of valuesAVG(A.UNT_TAKEN_PRGRSS)
COUNTcounts rowsCOUNT(A.EMPLID)
MAXmaximum value in the fieldMAX(A.ADMIT_TERM)
MINminimum valueMIN(A.ADMIT_TERM)
SUMcalculate sumSUM(A.UNT_TAKEN_PRGRSS)

Back to top

Converting Values

FunctionUsageExample
LOWERconverts a string to all lowercase charactersLOWER(A.STATE)
UPPERconverts a string to all upper case charactersUPPER(A.STATE)
INITCAPconverts a string to initial capital letterINITCAP(A.FIRST_NAME)
SUBSTRextracts a portion of a string or field
SUBSTR(field, position, length)
SUBSTR(A.ACAD_PROG, 1, 1)
|| (concatenation)combines two or more fields or valuesA.ACAD_CAREER || ' - ' || A.ACAD_PROG

Back to top

Numeric Function

FunctionUsageExampleResults
ROUND

Returns a number rounded to x number of decimal points

ROUND(field, decimal place)
The default decimal place is 0.

ROUND(A.CUM_GPA,2)3.596 → 3.60
TRUNC

Returns a number truncated to x number of decimal points

TRUNC(field, decimal place)
The default decimal place is 0.

TRUNC(A.CUM_GPA)3.596 → 3

Back to top

Free text

You can create a new field with any text or blank field.

For example, if you put 'Hello' on the expression text box, the new field will return Hello for all rows.

To create blank field, use single quote, blank space, and single quote:

free text

Back to top

CASE statement

Case statements can be useful when

  • translating values
  • limiting results to specific values based on criteria
  • returning different values or splitting one field into multiple values

Structure of case statement:

case statement format

Example - case statement
/*+Institution short desc*/
CASE
WHEN A.INSTITUTION = 'UMS01' THEN 'UMA'
WHEN A.INSTITUTION = 'UMS02' THEN 'UMF'
WHEN A.INSTITUTION = 'UMS03' THEN 'UMFK'
WHEN A.INSTITUTION = 'UMS04' THEN 'UMM'
WHEN A.INSTITUTION = 'UMS05' THEN 'UM'
WHEN A.INSTITUTION = 'UMS06' THEN 'USM'
WHEN A.INSTITUTION = 'UMS07' THEN 'UMPI'
ELSE 'Check'
END
Please go to Expression Libraries page for more examples.

Back to top

Date/Time

Select Expression Type as Date, Datetime or Time 

UsageExampleSelected Expression TypeOriginal dataResult in new field
today's date

SYSDATE

Date, Datetime or Time 
03/24/2022
add daysTO_DATE(A.GRADUATION_DT) - 365Date, Datetime or Time 05/24/202105/24/2022
get difference (in days)TO_DATE(SYSDATE) - TO_DATE(A.POSITION_ENTRY_DT)Date, Datetime or Time SYSDATE = 3/25/2022
POSITION_ENTRY_DT = 9/1/2017
1666
calculate months between two daysMONTHS_BETWEEN (SYSDATE, A.POSITION_ENTRY_DT)CharacterSYSDATE = 3/25/2022
POSITION_ENTRY_DT = 9/1/2017
54.78
calculate years between two days

(TO_DATE(SYSDATE) - TO_DATE(A.POSITION_ENTRY_DT))/365.25

TRUNC((TO_DATE(SYSDATE) - TO_DATE(A.POSITION_ENTRY_DT))/365.25)

CharacterSYSDATE = 3/25/2022
POSITION_ENTRY_DT = 9/1/2017
4.5
4 (when it is truncated)
convert date to characterTO_CHAR(CENSUS_DT, 'MMDDYYYY')Character10/15/202210152022
get month nameTO_CHAR(CENSUS_DT, 'Month')Character10/15/2022October
get year from date fieldSUBSTR(CENSUS_DT, 1,4)Character10/15/20222022


IMPORTANT NOTE
When you use Add Field function in the edit expression, the application will insert the field's alias, A.  You need to either delete the "A." characters or enter the field freeform to make the field operate as a date field and not a character field.

Back to top

Partition over

Please go to Aggregate and Analytic Functions- Partition Over/Partition By etc. page

Back to top

LISTAGG

  • combine multiple data rows in to one row
  • LISTAGG is aggregate function, so you need to check the aggregate function box

  • Format: LISTAGG(field_name, ',' ) WITHIN GROUP (order by field_name)

Please go to Flattening a File - Multiple Rows to Single Row page for examples.

Back to top

Regular Expressions

  • REGEXP_SUBSTR
    • finds and returns values meeting pattern within a string or substring
    • can use wildcards (^ , $, .)
    • returns matching values
  • REGEXP_INSTR
    • finds and return the character position of the matching value within a substring
    • returns a numeric position number
  • REGEXP_COUNT
    • tells you number of times you pattern is met
    • returns a numeric count
  • REGEXP_REPLACE
    • finds pattern and replaces with values that you specify
    • returns original pattern, but with substituted values

Back to top

Join PS Query Group!

Have you joined UMS PS Query User Group yet? You can ask questions or share tips and more.

Tips

  • Try to create a new expression one at a time and make sure if it works. 
  • Use header name with /*+ */
    Example: /*+description for special*/
  • Use Notepad++ 
    • Easier to read / Copy & Paste/ Replace
    • Helps to check the numbers of parentheses

Attachments:

image2022-2-25_11-47-17.png (image/png)
image2022-2-25_11-42-38.png (image/png)
image2020-6-2_9-26-15.png (image/png)
image2020-6-2_9-24-13.png (image/png)
CS HR Add to Favorites.jpg (image/jpeg)
Dashboard.JPG (image/jpeg)
image2019-11-4_10-48-52.png (image/png)
image2018-10-1_13-55-39.png (image/png)
image2018-10-1_13-50-28.png (image/png)
Query Search.jpg (image/jpeg)
Run to HTML or EXCEL.jpg (image/jpeg)
HR_FNfilepathStep1.jpg (image/jpeg)
LaunchPad.jpg (image/jpeg)
image2017-10-25_15-45-35.png (image/png)
image2017-10-25_15-15-42.png (image/png)
image2017-10-25_14-54-10.png (image/png)
HR_FNfilepathStep2.JPG (image/jpeg)
Help-button-800px.png (image/png)
Using the Advanced Search Tool in Query Viewer.PNG (image/png)
Advanced Search Dropdown Menu.PNG (image/png)
Query viewer advanced search.PNG (image/png)
Query search dropdown menu.PNG (image/png)
QS3.PNG (image/png)
QS2.PNG (image/png)
QS1.PNG (image/png)
image2022-3-23_17-3-55.png (image/png)
image2022-3-23_17-5-57.png (image/png)
image2022-3-23_17-20-40.png (image/png)
image2022-3-23_17-30-25.png (image/png)
image2022-3-24_9-43-53.png (image/png)
image2022-3-24_10-32-19.png (image/png)
image2022-3-24_10-52-47.png (image/png)
worddav24f187d98e87aa2308738207f767b8dc.png (image/png)
worddav91437d78072e7de44046479ce8949783.png (image/png)
worddav5d4a8badbfd280cf84b5aaf5d02ad9e9.png (image/png)
worddav74a308b13873c96e7447c68c6b54765a.png (image/png)
worddavdb4a04410be2d81ca988327595924465.png (image/png)
worddav0568c48bfb80c1bf702d4d666a4d74ef.png (image/png)
worddav91437d78072e7de44046479ce8949783.png (image/png)
image2022-3-24_15-12-21.png (image/png)
image2022-3-24_15-13-0.png (image/png)
image2022-3-25_9-13-55.png (image/png)
image2022-3-25_11-34-34.png (image/png)