--- title: "Calculations - Custom / Direct SQL" slug: "calculations-custom-direct-sql" description: "Lasernet FO Connector 6.1 and later contains the option to fetch and make calculations through direct SQL in the Query-Wizard." tags: ["Calculations", "Direct SQL expression ", "FO general information", "Custom properties"] updated: 2026-02-19T10:30:12Z published: 2026-02-19T10:30:12Z canonical: "kb.lasernetgroup.com/calculations-custom-direct-sql" --- > ## Documentation Index > Fetch the complete documentation index at: https://kb.lasernetgroup.com/llms.txt > Use this file to discover all available pages before exploring further. # Calculations - Custom / Direct SQL Lasernet FO Connector 6.1 and later includes the option to fetch and perform calculations via direct SQL in the Query Wizard. For example, this is useful for calculations or for using an SQL function to round a number. You can use any SQL functions with the **Custom/Direct SQL** in the Query Wizard. The Direct SQL runs across all companies within Dynamics 365 Finance and Operations, so it is important to use **Cross company** and specify the current company (**dataAreaId**) when data is required only for the current company. ## Example of Use The following example illustrates how to multiply the sum of the **SalesQty** by the **NetWeight**. 1. Select **Yes** in both the **Group by** and in **Cross company**. The tables **SalesTable** are renamed to **SalesTableQuery** to ensure it is possible to use the proper table names in the SQL statement. ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/calc1(1).png) 1. Add the fields that are required for the **WHERE-clause** in the SQL statement. In the following the fields **SalesId** and **dataAreaId** are added: ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/calc2(1).png) 1. Add a field that is used as a placeholder field - the placeholder field will return the value from the SQL statement and not the value from the field. In the following image, a number is required, and the number field is therefore added as a placeholder field. 1. Select **Custom** for the field. ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/calc3(1).png) 1. Add the following statement in the **Direct SQL,** which multiplies the **SalesQty** from **SalesLine** with the **NetWeight** from **InventTable**. The tables **SalesLine** and **InventTable** are the tables at the SQL server and are used for the select statement. > [!NOTE] > Note: > > It is important to use the proper table names in the SQL statement and to use the data-source name added in the **Query Wizard** for the "WHERE” clause. **SELECT Round(SUM(SalesLine.SalesQty*InventTable.NetWeight),1) from SalesLine join InventTable on InventTable.ItemId=SalesLine.ItemId AND InventTable.dataAreaId = SalesLine.dataAreaId where SalesLine.SalesId=SalesTableQuery.SalesId AND SalesLine.dataAreaid=SalesTableQuery.dataAreaid** ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/calc4(1).png) 1. Add a range containing the **dataAreaId** to ensure only records from the current company are fetched. The XML file will have the fields **SalesId** and **dataAreaId** and the field **CasDiscPercent** contains the sum of **SalesQty** multiplied with **NetWeight** rounded to 1 decimal for all the saleslines: ![calc6](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/calc6.png)