Allowed functions
Lists the available functions that can be used in expressions within the dynamic slicer data JavaScript object.
The following is a list of functions that report designers can use in expression, selectConditions, conditions and possibly other property definitions of the JavaScript slicer dynamic data definition object.
Now)
Returns the current date and time.
DateAdd (periodType, date, number)
Adds a defined number of periods to a date.
periodType [string] options:
- y = year
- M = month
- w = week
- d = day
- h = hour
- m = minute
- s = second
- ms = millisecond
date [date or date string] is a date to add to.
number [integer] is the number of period to add (or subtract if it is a negative integer)
Example:
DateAdd('M', Now(), -3)
Will subtract three months from the current date.
DateDiff (periodType, start, end, completePeriodsOnly)
Returns a number representing the number of periods that fit between the start and end dates.
periodType [string] is the same as in the DateAdd function.
start and end [date or date string] are the two limit dates between which we want to know the number of periods.
completePeriodsOnly [boolen] If true it will return the number of full periods that fit between the limit dates. If false (default), common rounding will be applied.
Example:
DateDiff('M', '23/Nov/2024 14:55', '1/Dec/2024 18:01', true)
Will return 0 since there is not a single full months between the limit dates.
GetDate (date, adjustForTimezone)
Converts a date string a an actual date object.
date is the actual date string to convert. These can be in the ISO format as well or a Unix date integer.
adjustForTimezone will adjust the date to the current time zone. This can be used if the source string is in a UTC format but the actual date/time needs to be presented for the current time zone.
Example:
GetDate('20240915T155300Z', true)
Will return '15 September 2024, 07:53:00' if the browser was running in Brisbane, Australia.
FormatDate (date, format, adjustForTimezone)
Formats a date object to a string of a defined format.
date [date or date string] is the date to be formatted. It can be a date object or date string, in which case the GetDate() function described above is used internally to convert it to a date object first.
format [string] is a format to be used like 'd MMM yy H:mm' which will result in a date string like: '9 Jan 24 6:58' if the passed-in date is '9 January 2024, 6:58:33.254 AM'.
The formatting options are:
d, dd, ddd or dddd for the day to be displayed as '9', '09', 'Sat' or 'Saturday'
MM, MMM or MMMM for the month to be displayed as 'Ja', 'Jan' or 'January'
yy or yyyy for the year to be displayed as '24' or 2024
h, hh, H or HH for the hour to be shown as '6', '06', '6' or '06' for 6 AM and '4', '04', '16' or '16' for 4 PM.
mm for the minutes to be shown as '58'
ss for the seconds to be shown as '33'
nnn or sss for the milliseconds to be shown as '254' or '25'
t or tt for the AM/PM time to be shown as 'A' or 'AM'
Example:
FormatDate('20240915T155300Z', 'ddd htt', true)
Will return 'Sun 7AM' if the browser was running in Brisbane, Australia.
FY (date, getEnd)
Returns the start or end of the financial year to which the date belongs to.
date is the date we want to find a financial year for.
getEnd If true this will result in returning the last day of the financial year. If false or omitted it will return the first day of the financial year.
Example:
FY(Now(), true)
Will return '30 June 2025' if the current organization was from Australia where the financial year starts in July and if the current date was for example 1st December 2024.
CY (date, getEnd)
Returns the first or last day of the current year.
date is the date we want to find a current year for.
getEnd If true this will result in returning the last day of the current year which will always be 31 December. If false or omitted it will return the first day of the year will be returned, which will always be 1 January.
Example:
CY(Now())
Will return '1 January 2024' if the current date was for example 1st December 2024.
Year (date)
Returns an integer representing the date's year.
Month (date)
Returns an integer representing the date's month.
Day (date)
Returns an integer representing the date's day.
GetMonthsSinceStartOfFinancialYear
(includeCurrentUnfinishedMonth, orMin, date, reverseOrder)
Returns and integer representing the number of months that has passed since the start of financial year.
includeCurrentUnfinishedMonth Set to true if the current unfinished month should be included in the count.
orMin If specified than the count will start from the start of the previous financial year if the number of months since the start of the current financial year is less then this number.
date An optional date to which to count the months. If omitted the current date is automatically used.
reverseOrder Will reverse the order of the dates in the resulting array, going from the youngest to the oldest.
Example:
GetMonthsSinceStartOfFinancialYear(true, 3, '2 Aug 2024')
Will return the following array of dates
[
'1 July 2023, 00:00:00',
'1 August 2023, 00:00:00',
'1 September 2023, 00:00:00',
//...10 more months here omitted for brevity
'1 Aug 2024, 00:00:00'
]
if the current organization is an Australian one an therefore has its financial year starting on 1st July. Since the date was specified and that date is only 2 months into the new financial year and the orMin (or minimum number of months) parameter was specified as 3, which is higher than 2, then the start of financial year used by this function to calculate the number of months was used from the past financial year.
DatePeriods (parameterObject)
This is a generative function which generates an array of date periods.
Since this function has too many possible input parameters and its combinations a parameter object is used instead to specify the required combination of these parameters.
The parameterObject properties
periodType The type of the period to generate. The options here are the same as for the DateAdd function described also in this document.
step Specifies the number of steps to take for each following date generated. Can be a negative integer if each next date should be smaller as opposed to higher than the last.
DO NOT:
Do not combine negative value in step with a negative value in periods!!!
startDate The start date from which to start generating the values. Can be omitted if at least the endDate is specified.
endDate The end date past which the generated dates should not reach. Can be omitted if at least the startDate is specified.
Note that:
...the start date can be higher than end date if d wish to have the dates generated in descending order.
reverseOrder Set to true if you wish to have the dates generated in reverse order. This property may be useful if you only can specify the start or end date, but not both.
periods Lets you specify the maximum number of periods to generate. This parameter is compulsory if only one of the limit dates (start or end) is specified. It can be a negative number if the date sequence should go down instead of up from the current or passed-in date. If this value is negative it is the same as having a negative step value. However, do not combine negative value in periods with a negative value in step!!!
Also note that:
...the maximum number of dates in the resulting array may be smaller than you specified in the periods parameter if you also have both of the limit dates specified. The period generation ends once either the number specified in periods is reached or the other limit date.
includeCurrentPeriod If true then the current unfinished period will be included in the list of generated dates.
resetTime If true (default) than the time will be set to 00:00:00. If false the current time at the time of this function call will be kept.
day Lets you specify a concrete day in a month in the generated dates.
month Lets you specify a concrete month in a year in the generated dates.
year Lets you specify a concrete year in the generated dates.
hour Lets you specify a concrete hour in the generated dates.
minute Lets you specify a concrete minute in the generated dates.
second Lets you specify a concrete second in the generated dates.
Example:
DatePeriods({periodType: 'y', startDate: Now(), periods: -3})
Will return an array of past three years starting from the current date. So if Now() is "3 January 2025, 6:58:33.254 AM" then this function will produce the following array:
[
'3 January 2025, 00:00:00',
'3 January 2024, 00:00:00',
'3 January 2023, 00:00:00'
]
The time is reset as the default for resetTime is true.
GetNthMember(array, index)
Returns a single value from an array found at index passed in the second parameter.
array Any array of values from which a single value will be selected.
index The index of the array item to be returned. Can be a negative value in which case the actual index is counted from the end of the array.
Example:
GetNthMember(GetMonthsSinceStartOfFinancialYear(false, 1), -1)
Will return the last date from the array returned by the GetMonthsSinceStartOfFinancialYear function.