Overview
Use the BC.QUERY function to return a list of objects of a specified Business Central object type (as either an Excel array or an Excel table), filtered to match provided criteria.
You can use the Query Builder functionality to construct formulas visually.
Syntax
=BC.QUERY(
ConnectionName,
Object,
Filter,
Select,
IncludeHeader,
Settings,
TableOutputCell
)
Arguments
The BC.QUERY function uses the following arguments:
|
Argument |
Required / Optional |
Description |
|---|---|---|
|
|
Optional |
Provide one of the following values:
OR Omit the argument to return results for all compatible connections with default aggregation settings. |
|
|
Required |
Business Central object name (e.g., Use the BC.EXPANDOBJECTRANGE function to retrieve the list of Business Central objects with information on their insertability, updatability, and deletability. Objects without an ID field cannot be queried. Certain objects (for example, |
|
|
Optional |
OData4 query based on the fields in the object. OData4 operators are supported, including: You can use the BC.QUERYFILTER function to generate filters ready to use with BC.QUERY. |
|
|
Optional |
Comma-separated list of object fields to be included in the resulting dataset; also for related objects (for example, In case of objects nested within the queried object, you can also use the
Rows where the selected columns have no value are included in the results - see Rows with no value in selected columns. Rows where the selected columns have no value are included in the results - see Rows with no value in selected columns. |
|
|
Optional |
|
|
|
Optional |
Two-dimensional array
|
|
|
Optional |
If the argument is specified, the function output is represented as an Excel table, and the first column in the If the argument is omitted, the result is returned as an array. |
Rows with no value in selected columns
The function returns all matching rows, including rows where the selected columns have no value. Blank cells in the results are expected and are not an error. A row appears entirely blank only when none of the selected columns has a value for that record.
Because every matching record produces a row, the spilled range sizes to the number of matching records, not to the number of populated values. Account for this in any downstream formula or conditional formatting that depends on the size of the result.
To exclude rows with no value in a column, add a condition to the Filter argument.
=BC.QUERY(
"bc",
"agedAccountsPayables",
BC.QUERYFILTER("bc","agedAccountsPayables",,,"vendorNumber","<> null"),
"vendorNumber"
)
Description: Returns the vendorNumber column from agedAccountsPayables, excluding rows where vendorNumber has no value.
Excel Online
Important: Loading large datasets with BC.QUERY is not performant in Excel Online due to the limitations of the Excel platform in the browser. If your dataset contains more than approximately 100,000 records, we strongly recommend using a desktop version of Excel 365 for Windows or Mac OS.
Examples
First ten records
=BC.QUERY(
"BC",
"generalLedgerEntries",
,
,
,
10
)
Description: Returns the first 10 records found for the Object generalLedgerEntries.
Filters and column selection
=BC.QUERY(
"BC",
"salesinvoices",
"sellToState eq 'ON' and status eq 'Paid'",
"number,customerNumber,invoiceDate,totalAmountExcludingTax"
)
Description: Returns the number, customerNumber, invoiceDate and totalAmountExcludingTax fields for all salesInvoices object with the status Paid, issued to customers in the province of Ontario.
Querying objects that require filtering
Certain Business Central objects require additional filtering to be queried. For instance, when you try to query the journalLines object without filters, you will receive an error:
This object requires you to provide a filter for the batch ID or journal ID field, for instance:
=BC.QUERY(
"BC",
"journallines",
"journalid eq 42009fff-9023-ef11-840f-6045bde9c820"
)
Description: Returns all entries for the journalLine object with journal ID equal to 42009fff-9023-ef11-840f-6045bde9c820 for the connection BC
Using the ‘unpivot’ selection method for nested objects
=BC.QUERY(
"BC",
"journalLines",
"journalId eq 375762c3-e6d7-ef11-9344-6045bdc8a19b",
"accountNumber, unpivot(dimensionSetLines.code, dimensionSetLines.valueCode)"
)
Description: Queries the journalLines object filtered for the journalId field to equal 375762c3-e6d7-ef11-9344-6045bdc8a19b. Returns values from the accountNumber property in the first column.
unpivot is used to create columns based on the key value dimensionSetLines.code, and the columns are populated with data retrieved from the value field dimensionSetLines.valueCode where appropriate values are available.
Query web-services API objects
=BC.QUERY(
"BC",
"Vendors",
,
"id, number, displayName, email",
,
{"api";"web-service"}
)
Description: Queries the id, number, displayName fields in the web-services API object Vendors for the connection BC.