Built-in Functions → weekStartDate
weekStartDate() is a scalar date function that returns the date of the first day of the current week.
A week starts on Sunday and ends on Saturday.
Signature
weekStartDate()
Returns
Date
representing the first date of the current week.
Example
Consider the following table as a sample data:
Date Quarter Month Sales Amount5/22/2021 Q2 M5 1005/21/2021 Q2 M5 2005/23/2021 Q2 M5 1004/22/2021 Q2 M4 1505/20/2021 Q2 M5 2506/22/2021 Q2 M6 1503/22/2021 Q1 M3 2005/10/2021 Q2 M5 2505/01/2021 Q2 M5 3005/09/2021 Q2 M5 1005/30/2021 Q2 M5 502/22/2021 Q1 M2 50
Consider a case where you want to identify the start of the current week and the sales amount that occurred after that date, for example, the current week is 5/22/2021.
- Start date of the current weekweekStartDate()
Sales after the week start date
SALES_ACME.SALES.TIME_ID >= weekStartDate()
This example returns all Sales amount that occurred after the start of the current week.
Quarter | Date | Sales Amount |
---|---|---|
Q2 | 5/22/2021 | 100 |
Q2 | 5/23/2021 | 100 |
Q2 | 6/22/2021 | 150 |
Q2 | 5/30/2021 | 50 |
Use the following steps for detailed instructions on how to use the weekStartDate() date function:
The sample data is uploaded, and then added and loaded into a Schema named SALES_Acme. For more information on creating a data source and a schema, refer to the Guides→Start document.
- 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 Data panel, select Manage Dataset (+).
- In the Manage Data Sets panel, in Tables, select SALES_Acme. Close the panel.
- From the Data panel, drag and drop the following columns to the respective tray:
- From the SALES table, drag and drop Quarter to the Grouping Dimension tray.
- From the SALES table, drag and drop Sales Amount and Date to the Measure tray.
- In the Properties panel for Sales Amount:
- For Format, select Dollar Rounded.
- From the Data panel, drag and drop Add Formula to the Individual Filter tray.
- The Formula Builder automatically opens:
- In Search Functions, select the down arrow, and then select Date Functions.
- Double-click the weekStartDate function,
weekStartDate()
, to add the formula to the editor. - In the Formula Editor, use the following condition:
SALES_ACME.SALES.TIME_ID >= weekStartDate()
- Select Validate & Save.
- In the Measure tray, double-click the New Formula pill and rename it to weekStartDate().
- Name the insight Sales per Quarter After Current Week Start Date.
- In the Action bar, select Save.