quarter function in the Factory

The quarter function returns the first month of the corresponding quarter of the date attribute. The results will always be:

  • 1, if the date attribute is in the first quarter, from January to March;

  • 4, if the date attribute is in the second quarter, from April to June;

  • 7, if the date attribute is in the third quarter, from July to September;

  • 10, if the date attribute is in the fourth quarter, from October to December.

If the extract parameter is True, the corresponding quarter is displayed.


Parameters

quarter(date, extract)

Parameter

Description

date

The date, week, month, quarter or datetime attribute if the extract parameter is False to retrieve the month value.

If the extract parameter is True, all attribute types can be used. The date parameter is mandatory.

extract

A binary value (True/False) which is set as False as default.

If True, the function returns the corresponding quarter.

The binary parameter values (True/False) are case sensitive.

Date type valid formats (if the values aren’t this format, the function will return an error).

  • 2019/10/12;

  • 12/10/2019;

  • 2019-10-12;

  • 12-10-2019;

  • 2019/Oct/12;

  • 12/Oct/2019;

  • 2019-Oct-12;

  • 12-Oct-2019.

Week type valid formats (if the values aren’t this format, the function will return an error).

  • 2019/W41;

  • W41/2019;

  • 2019-W41;

  • W41-2019.

Month type valid formats (if the values aren’t this format, the function will return an error).

  • 1492/10;

  • 10/1492;

  • 1492-10;

  • 10-1492;

  • 1492/Oct;

  • 1492-Oct;

  • Oct/1492;

  • Oct-1492.

Quarter type valid formats (if the values aren’t this format, the function will return an error).

  • 2019/Q3;

  • Q3/2019;

  • 2019-Q3;

  • Q3-2019.

Datetime type valid formats (if the values aren’t this format, the function will return an error).

  • 2019/05/22 17:33:45


Example

The following example uses the Instagram_data dataset.

Description

Screenshot

In this example, we want to retrieve the quarter of the Date Posted attribute. We want to be displayed the first month of the date’s corresponding order, so the formula will be:

quarter($"Date Posted")

The results can be read as follows:

  • From rows 1 to 13, the quarter of the year where the posts were published begins with 4, so it refers to the second quarter, beginning with April (month number 4) and ending with June.

In the following examples, you will see how the extract parameter changes the results.

Description

Screenshot

In this example, we want to retrieve the quarter of the Date Posted attribute. As we want the exact quarter, and not its first month, we need to specify the extract parameter as True.

Add a new attribute, called quarter, and type the following formula:

quarter($"Date Posted",True)

This function returns completely different results when working using attributes whose type is different from those specified in the date parameter’s description:

  • In this use case, the starting date from which the function calculates the quarter is the default Rulex date, which is 1899-12-30, in order to return the corresponding date.

Description

Screenshot

In this example, we want to retrieve the quarter of the Month attribute.

As its type is integer, the function must contain also the extract parameter.

Add a new attribute and type the following formula:

quarter($"Month",True)

As you can see, the function has returned values in quarter format.

The Month attribute’s values are considered as the number of days to add to the default Rulex date, 1899-12-30:

  • In row 1, for example, the function has returned 1900-Q1: the Month attribute’s value is 5, so the software considers 5 as the number of days to add to the default Rulex date, which becomes 1900-01-04. As January is in the first quarter of the year, the function returns 1900-Q1.