Skip to main content
Announcements
Customer Spotlight: Discover what’s possible with embedded analytics Oct. 16 at 10:00 AM ET: REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
varunreddy
Creator III
Creator III

Creating a variable in the script

Hi All,

I have a quick question.I am able to create a variable using variable overview but unable to create it using the script. I know it is silly question. Just wanted to know why I am unable to create in the script.

Calculation Used:

vmaxdate = max(Date)

Thanks in advance!

Best Regards,

Varun Reddy

1 Solution

Accepted Solutions
Peter_Cammaert
Partner - Champion III
Partner - Champion III

Two reasons

  • Script aggregation functions can only be used in LOAD statements.
  • Because you use max() outside of any LOAD statement, it will return the NULL value. Assigning NULL to a variable will effectively delete the variable (if you didn't create it in the Variable Overview first)

If, for instance, field Date is present in a resident table called Calendar, you better use something like this:

MinMaxTable:

LOAD max(Date) AS vMaxDate  // Creates a single row with a single value

RESIDENT Calendar;

LET vmaxdate = peek('vMaxDate'); // peek into the table and get that single value

DROP Table MinMaxTable;

Best,

Peter

View solution in original post

3 Replies
Peter_Cammaert
Partner - Champion III
Partner - Champion III

Two reasons

  • Script aggregation functions can only be used in LOAD statements.
  • Because you use max() outside of any LOAD statement, it will return the NULL value. Assigning NULL to a variable will effectively delete the variable (if you didn't create it in the Variable Overview first)

If, for instance, field Date is present in a resident table called Calendar, you better use something like this:

MinMaxTable:

LOAD max(Date) AS vMaxDate  // Creates a single row with a single value

RESIDENT Calendar;

LET vmaxdate = peek('vMaxDate'); // peek into the table and get that single value

DROP Table MinMaxTable;

Best,

Peter

varunreddy
Creator III
Creator III
Author

Thanks Peter,

Best Regards,

Varun

swuehl
MVP
MVP

Just use SET statement:

Set vmaxdate = max(Date);

Set vmaxdate2 = '=max(Date)';

Set vmaxdate3 = =max(Date);