Built-in Functions → quarterWeek

quarterWeek() is a conversion function that returns the week number of the quarter from the beginning of the quarter for a given date or timestamp, where a week starts on Sunday and ends on Saturday.

Note

To return the quarter’s week number for the current date, use the quarterWeek() conversion function without a parameter.

Signature

quarterWeek(date_timestamp exp)

The following table illustrates the quarterWeek() function parameter:

Parameter Description
date_timestamp exp The date or timestamp value to determine the quarter’s week number from

Returns

int representing the quarter’s week number for a given date or timestamp.

Examples

  • Identify the week number of the quarter for the given date, 04/24/2020.
quarterWeek(
	date(
		"2020-04-24"
	)
)

April 24th is in the fourth week of the second quarter (Q2: April, May, and June). Thus, the quarterWeek() is 4.

  • Identify the week number of the quarter for the given timestamp, 02/06/2021 03:09:11.
quarterWeek(
	timestamp(
		"2021-02-06 03:09:11"
	)
)

February 6th is in the sixth week of the first quarter (Q1: January, February, and March). Thus, the quarterWeek() is 6.

The following table illustrates the behavior of the quarterWeek() conversion function:

Product Revenues quarterWeek(date) quarterWeek(timestamp)
CD $200 4 6
Hard disk $600 4 6
Cable $550 4 6

Use the following steps for detailed instructions on how to use the quarterWeek() conversion function to tackle the first example above in an insight:

Note

In the Cluster Management Console (CMC), create a tenant that includes Sample Data. The Sample Data includes the SALES schema.

  • In the Navigation bar, select the Content tab, and then select + New → Add Dashboard.
  • In the Add Dashboard dialog, for Name, enter Product Dashboard, and then select Add.
  • In the Action bar, select + (add icon), or select + Add Insight.
  • In the Insight panel, select Listing Table or V.
  • In Tables, select Aggregated Table.
  • In the Data panel, select Manage Dataset.
  • In the Manage Data Sets panel, in Tables, select SALES. Close the panel.
  • From the Data panel, drag and drop the following columns to the respective tray:

    • Category from the PRODUCTS table to the Grouping Dimension tray.
    • Revenue from the SALES table to the Measure tray.

      • In the Properties panel, for Number Format, select Dollar Rounded.
  • From the Data panel, drag and drop Add Formula to the Grouping Dimension tray.
    The Formula Builder automatically opens:

    • In Search Functions, select the down arrow, and then select Conversion Functions.
    • Double-click the first quarterWeek function, quarterWeek(date_timestamp exp), to add the formula to the editor.
    • In the Formula Editor, replace date_timestamp exp with date("2020-04-24")
    • Select Validate & Save.
  • In the Properties panel, for Column Label, enter quarterWeek().
  • Name the insight Revenue Per Category.
  • In the Action bar, select Save.