Installation
The Query library is available on npmOverview
- .select
- .where
- .groupBy
- .orderBy
- .limit
- .offset
- .dateGrain
- .previousPeriod
- .rollingPeriod
- .periodToDate
- .useFiscalCalendar
- .useBeastModes
- Aggregation
- Date filtering
- Date range filtering
Examples
- Basic Query
- Max Date
- With Domo.js
Usage
Building a Query
This section will explain the options available to you for building queries. Here is an example of a complex query.Note:
- Refer to the Date Range Filtering section for accepted values for the
dateGrainandperiodToDatefunctions.- Refer to the Order By section for accepted values for the
orderByfunction.
Selecting Columns
Useselect to specify the column names for the columns you want returned.
Column names are the alias names specified in the manifest.json file.
Data Filtering
Filter data by using thewhere(columName) function followed by the desired filter function.
Filter Functions
Date Filtering
Thelt, lte, gt, gte, between filter functions will filter dates when used on a column that is a date. Other functions will treat the date as a string.
Date Range Filtering
Columns that are dates can be filtered using specific ranges:previousPeriod, rollingPeriod, periodToDate.
NOTE: Only 1 date range filter may be used in a query.A
DateGrain enum and a RollingDateGrain enum are provided with the valid interval options. These are:
Previous Period
Data for last year, last month, etc can be requested by using thepreviousPeriod function. This is how you would get data from last year when the date column is named salesdate:
Note:
- Refer to the Date Range Filtering section for accepted values for the
DateGrainparameter.
Rolling Period
A rolling period can be requested by using therollingPeriod function. For example, this is how you would get all data from the last 6 months when your date column is named salesdate:
Note:
- Refer to the Date Range Filtering section for accepted values for the
RollingDateGrainparameter.
Period to Date
Period-to-date filtering is done using theperiodToDate function. For example, this is how you would get year to date data when the date column is named salesdate:
Note:
- Refer to the Date Range Filtering section for accepted values for the
DateGrainparameter.
Group By
Data can be transformed to a group-by operation using thegroupBy function.
Aggregations for columns can be specified in an object where the key is the column name, and the value is an Aggregation.
By default, columns are counted.
Note:
- Refer to the Aggregation section for accepted values for the
Aggregationparameter.
| color | shape | quantity |
|---|---|---|
| red | square | 3 |
| green | square | 14 |
| blue | square | 4 |
| purple | square | 9 |
| orange | circle | 3 |
| red | circle | 14 |
| green | circle | 4 |
| blue | circle | 9 |
| purple | triangle | 3 |
| orange | triangle | 14 |
| red | triangle | 4 |
| green | triangle | 9 |
| blue | square | 3 |
| purple | square | 14 |
| orange | square | 4 |
| red | square | 9 |
| color | shape | quantity |
|---|---|---|
| red | 4 | 30 |
| orange | 3 | 21 |
| purple | 3 | 26 |
| green | 3 | 27 |
| blue | 3 | 16 |
Date Grain
Data can be “grained” by date by using thedateGrain function.
This is a special type of “group by”.
Note:
- Only 1 column may be date grained in a query.
- Refer to the Date Range Filtering section for accepted values for the
DateGrainparameter.
groupBy column aggregations may be specified.
Aggregation
Accepted aggregation values are'count', 'sum', 'avg', 'min', 'max', or 'unique'.
You can use data aggregations to
- Consolidate all rows of a column into a single value.
- Specify the aggregation type for date grain and group by queries.
aggregate function. For example, to specify the aggregations for fields salesTotal and salesAmount as sum and average respectively:
Order By
Rows can be ordered by any column in'ascending' or 'descending' order using the orderBy function.
An enum (OrderByDirection) is provided to define the order by direction. Valid orderings:
Limit
For improved performance and latency, you can paginate data usinglimit and offset.
Offset
To offset the data you get by a certain number, useoffset.
Fiscal Calendar
You can specify to use the instances fiscal calendar for date-related operations such aspreviousPeriod or dateGrain with useFiscalCalendar(true). The standard calendar is used by default.
Beast Modes
You can enable beast modes in the query by calling theuseBeastMode.
true