Different margins per order between 25.0 and 27.0
Replies happen on the forum.
Go to sourceQuestion
It appears that the gross margin in the sales data has changed between release 25.0 and release 27.0.
For example, order 20031765 has a margin in sorall@inmemorystorage of 50,15, but this was previously 56 plus cents.
Query to retrieve the margin:
select SOR_COSTPRICEQUANTITY
, POR_SUPPLIERCODE
, POR_SUPPLIERNAME
, POR_ORDERNUMBER
, margin
, margin_percentage
, sor_week
, sor_maand
, sor_Timestamp
, sor_AmountDC
, sor_AmountDiscount
, sor_AmountDiscountExclVat
, sor_AmountFC
, sor_AmountFCExclVat
, sor_ApprovalStatus
, sor_Approved
, sor_Approver
, null sor_CostCenter
, null sor_CostPriceFC
, null sor_CostUnit
, sor_Created
, sor_Creator
, sor_Currency
, null sor_CustomerItemCode
, sor_DeliverTo
, sor_DeliverToContactPerson
, sor_DeliveryAddress
, sor_DeliveryDate
, sor_DeliveryStatus
, sor_Description
, sor_Discount
, sor_Division
, sor_Document
, sor_ID
, sor_InvoiceStatus
, sor_InvoiceTo
, sor_InvoiceToContactPerson
, null sor_Item
, null sor_ItemVersion
, null sor_LineNumber
, sor_Modified
, sor_Modifier
, null sor_NetPrice
, sor_Notes
, sor_OrderDate
, sor_OrderedBy
, sor_OrderedByContactPerson
, sor_OrderID
, sor_OrderNumber
, sor_PaymentCondition
, sor_PaymentReference
, null sor_Pricelist
, sor_Project
, null sor_PurchaseOrder
, null sor_PurchaseOrderLine
, null sor_Quantity
, null sor_QuantityDelivered
, null sor_QuantityInvoiced
, sor_Remarks
, sor_Salesperson
, sor_SelectionCode
, sor_ShippingMethod
, null sor_ShopOrder
, sor_Status
, null sor_UnitCode
, null sor_UnitPrice
, null sor_UseDropShipment
, sor_VATAmount
, sor_VATCode
, sor_WarehouseID
, sor_YourRef
, sor_SalesChannel
, act_Timestamp
, act_Accountant
, act_AccountManager
, act_AccountManagerHID
, act_ActivitySector
, act_ActivitySubSector
, act_AddressLine1
, act_AddressLine2
, act_AddressLine3
, act_Blocked
, act_BRIN
, act_BSN
, act_BusinessType
, act_CanDropShip
, act_ChamberOfCommerce
, act_City
, act_Classification
, act_Classification1
, act_Classification2
, act_Classification3
, act_Classification4
, act_Classification5
, act_Classification6
, act_Classification7
, act_Classification8
, act_Code
, act_CodeAtSupplier
, act_CompanySize
, act_ConsolidationScenario
, act_ControlledDate
, act_Costcenter
, act_CostPaid
, act_Country
, act_Created
, act_Creator
, act_CreditLinePurchase
, act_CreditLineSales
, act_Currency
, act_CustomerSince
, act_DatevCreditorCode
, act_DatevDebtorCode
, act_DiscountPurchase
, act_DiscountSales
, act_Division
, act_Document
, act_DunsNumber
, act_Email
, act_EndDate
, act_EstablishedDate
, act_Fax
, act_GLAccountPurchase
, act_GLAccountSales
, act_GLAP
, act_GLAR
, act_GlnNumber
, act_HasWithholdingTaxSales
, act_ID
, act_IgnoreDatevWarningMessage
, act_IntraStatArea
, act_IntraStatDeliveryTerm
, act_IntraStatSystem
, act_IntraStatTransactionA
, act_IntraStatTransactionB
, act_IntraStatTransportMethod
, act_InvoiceAccount
, act_InvoiceAttachmentType
, act_InvoicingMethod
, act_IsAccountant
, act_IsAgency
, act_IsAnonymised
, act_IsBank
, act_IsCompetitor
, act_IsExtraDuty
, act_IsMailing
, act_IsMember
, act_IsPilot
, act_IsPurchase
, act_IsReseller
, act_IsSales
, act_IsSupplier
, act_Language
, act_Latitude
, act_LeadPurpose
, act_LeadSource
, act_Logo
, act_LogoFileName
, act_LogoThumbnailUrl
, act_LogoUrl
, act_Longitude
, act_MainContact
, act_Modified
, act_Modifier
, act_Name
, act_OINNumber
, act_Parent
, act_PayAsYouEarn
, act_PaymentConditionPurchase
, act_PaymentConditionSales
, act_Phone
, act_PhoneExtension
, act_Postcode
, act_PriceList
, act_PurchaseCurrency
, act_PurchaseLeadDays
, act_PurchaseVATCode
, act_RecepientOfCommissions
, act_Remarks
, act_Reseller
, act_RSIN
, act_SalesCurrency
, act_SalesTaxSchedule
, act_SalesVATCode
, act_SearchCode
, act_SecurityLevel
, act_SeparateInvPerProject
, act_SeparateInvPerSubscription
, act_ShippingLeadDays
, act_ShippingMethod
, act_StartDate
, act_State
, act_Status
, act_StatusSince
, act_TradeName
, act_Type
, act_UniqueTaxpayerReference
, act_VATLiability
, act_VATNumber
, act_Website
, act_DeliveryAdvice
, act_ShowRemarkForSales
, rowid$
from sorall@inmemorystorage
Preparatory trigger in Invantive Control for Excel:
declare
l_start_date date := to_date($X{startdate});
begin
create or replace table sim@inmemorystorage
as
select /*x http_disk_cache(true, true, interval '1 week') */
sim.division
, sim.item
, sim.itemcode
, sim.SupplierCode
, sim.SupplierDescription
from supplieritems sim
where sim.MainSupplier = true
;
create or replace table itm@inmemorystorage
as
select itm.*
, igp.code itemgroupcode
from itemsincremental itm
join itemgroups igp
on igp.id = itm.itemgroup
;
create or replace table gle8@InMemoryStorage
as
select id
from glaccountsincremental
where code like '8%'
;
create or replace table tle@inmemorystorage
as
select to_char(tle.date, 'YYYYIW')
tle_week
label 'Week'
, to_char(tle.date, 'YYYYMM')
tle_maand
label 'Maand'
, cast(-tle.amountdc as double)
amountdc
label 'Gefactureerde Omzet'
, itm.itemgroupcode
, tle.*
from gle8@InMemoryStorage gle
join transactionlinesincremental tle
on tle.date >= l_start_date
and tle.journalcode = '70'
and tle.glaccount = gle.id
and tle.linenumber not in (0, 9998, 9999)
join itm@inmemorystorage itm
on itm.id = tle.item
order
by tle.division
, tle.date
, tle.invoicenumber
, tle.linenumber
;
create or replace table sor@inmemorystorage
as
select to_char(sor.orderdate, 'YYYYIW')
sor_week
label 'Week'
, to_char(sor.orderdate, 'YYYYMM')
sor_maand
label 'Maand'
, sor.* prefix with 'sor_'
, act.* prefix with 'act_'
from SalesOrdersV2Incremental sor
join AccountsIncremental act
on act.id = sor.OrderedBy
where sor.orderdate >= l_start_date
;
--
-- Historische inkoopprijzen per artikel.
--
create or replace table purchaselines@inmemorystorage
as
select por.orderdate
, por.orderdate - to_number(to_char(por.orderdate, 'D'))
sun_in_week_date
, to_char(por.orderdate, 'YYYYIW')
por_week
label 'Week'
, to_char(por.orderdate, 'YYYYMM')
por_maand
label 'Maand'
, ple.itemcode
, ple.netprice
, ple.quantity
, por.ordernumber
from exactonlinerest..PurchaseOrders por
join exactonlinerest..PurchaseOrderLines ple
on ple.PurchaseOrderID = por.PurchaseOrderID
;
--
-- Maximum prijzen in een week waarin er inkopen geweest zijn
-- voor een artikel.
--
create or replace table pleweek@inmemorystorage
as
select itemcode
, por_week
, sun_in_week_date
, avg(quantity * netprice) netpricewavg
, avg(netprice) netpriceavg
, max(netprice) netpricemax
, min(netprice) netpricemin
, count(*) cnt
from purchaselines@inmemorystorage
group
by itemcode
, por_week
, sun_in_week_date
;
--
create or replace table purchaselinesmin@InMemoryStorage
as
select min(orderdate) orderdate
from purchaselines@inmemorystorage
;
--
-- Opzoektabel per week wanneer de laatste keer een artikel is ingekocht.
--
create or replace table plw@inmemorystorage
as
select clr.day_date
, plw.itemcode
, min(plw.por_week)
plw_por_week_min
, max(plw.sun_in_week_date)
plw_sun_in_week_date_min
from purchaselinesmin@InMemoryStorage pln
join CALENDAR@DataDictionary clr
--
-- Optimalisatie: kijk alleen vanaf de eerste besteldatum.
--
on clr.day_date >= pln.orderdate
and clr.day_in_week = 1
--
-- Optimalisatie: kijkt niet in de toekomst.
--
and clr.day_date <= add_months(trunc(sysdate), 1)
join pleweek@inmemorystorage plw
on plw.sun_in_week_date <= clr.day_date
group
by clr.day_date
, plw.itemcode
;
--
-- Bepaal per artikel wat de laatste bekende prijs is
-- per week. Als er meerdere prijzen zijn, dan wordt de hoogste
-- inkoopprijs genomen.
--
create or replace table approx_prices@inmemorystorage
as
select plw0.day_date
, plw0.itemcode
, plw0.plw_sun_in_week_date_min
, plw1.netpricemax
netpriceweek
from plw@inmemorystorage plw0
join pleweek@inmemorystorage plw1
on plw1.sun_in_week_date = plw0.plw_sun_in_week_date_min
and plw1.itemcode = plw0.itemcode
;
create or replace table sle@inmemorystorage
as
select sor.*
, sle.* prefix with 'sle_'
, coalesce(apeb.netpriceweek, apef.netpriceweek, itm.CostPriceStandard) * sle.quantity
sle_costpricequantity
label 'Kostprijs Artikelen'
, coalesce(por.suppliercode, sim.suppliercode)
por_suppliercode
, coalesce(por.suppliername, sim.supplierdescription)
por_suppliername
, por.ordernumber
por_ordernumber
, itm.code
sle_itemcode
label 'Artikelcode'
, itm.itemgroupcode
sle_itemgroupcode
, itm.costpricestandard
sle_costpricestandardcurrent
label 'Kostprijs Artikel Momenteel'
, apeb.netpriceweek
sle_costpriceapproximateb
label 'Kostprijs Artikel Historisch Terug'
, apef.netpriceweek
sle_costpriceapproximatef
label 'Kostprijs Artikel Historisch Vooruit'
, case
when apeb.netpriceweek is not null
then 'Vorige inkoop'
when apef.netpriceweek is not null
then 'Volgende inkoop'
else 'Standaard kostprijs'
end
herkomst
from sor@inmemorystorage sor
join SalesOrderLinesV2Incremental sle
on sle.orderid = sor.sor_orderid
join itm@inmemorystorage itm
on itm.id = sle.item
left
outer
join exactonlinerest..purchaseorders por
on por.purchaseorderid = sle.purchaseorder
-- Exclude: shipping
and itm.itemgroupcode != 'VK'
left
outer
join sim@inmemorystorage sim
on sim.item = sle.item
left
outer
join approx_prices@inmemorystorage apeb
on apeb.itemcode = itm.code
and apeb.day_date = sor.sor_orderdate - to_number(to_char(sor.sor_orderdate, 'D'))
-- Exclude: shipping
and itm.itemgroupcode != 'VK'
left
outer
join approx_prices@inmemorystorage apef
on apef.itemcode = itm.code
and apef.day_date = sor.sor_orderdate - to_number(to_char(sor.sor_orderdate, 'D')) + 7
-- Exclude: shipping
and itm.itemgroupcode != 'VK'
;
create or replace table sorcost@inmemorystorage
as
select sor_division
, sor_orderid
, sor_ordernumber
, sor_orderdate
, sum(sle_costpricequantity)
sor_costpricequantity
label 'Kostprijs Artikelen'
, min(por_suppliercode)
por_suppliercode
label 'Eerste Leverancier Code'
, min(por_suppliername)
por_suppliername
label 'Eerste Leverancier Naam'
, min(por_ordernumber)
por_ordernumber
label 'Eerste Leverancier Bestelnummer'
from sle@inmemorystorage
group
by sor_division
, sor_orderid
, sor_ordernumber
, sor_orderdate
;
create or replace table sorall@inmemorystorage
as
select cst.sor_costpricequantity
, cst.por_suppliercode
, cst.por_suppliername
, cst.por_ordernumber
, sor.sor_amountfcexclvat - cst.sor_costpricequantity
margin
label 'Bruto Marge'
, case
when sor.sor_amountfcexclvat != 0
then ( sor.sor_amountfcexclvat - cst.sor_costpricequantity )
/ sor.sor_amountfcexclvat
else 1
end
margin_percentage
label 'Bruto Marge %'
, sor.*
from sor@inmemorystorage sor
left
outer
join sorcost@inmemorystorage cst
on cst.sor_orderid = sor.sor_orderid
;
end;
Accepted answer
Thank you for the clear report and the attached query; with them the difference could be reproduced well.
Cause: Exact Online returns local time in a UTC notation
Exact Online returns a date or time via the REST API as /Date(milliseconden)/. According to the definition of that notation, the number counts the milliseconds since 1 January 1970 in UTC. Exact Online does, however, insert the Dutch clock time, with the summer or winter time that applied on that day.
For example: an order with an order date of 13 January 2026 is received as /Date(1768262400000)/. That is 13 January 00:00 UTC. If Exact Online really returned UTC, midnight in the Netherlands would have had to be /Date(1768258800000)/: 12 January 23:00 UTC. For a date in July, the difference would even be two hours. Exact Online returns midnight in both cases. The value therefore looks like UTC, but is the local clock time.
For a date without a time (order date, invoice date, posting date), this is not a problem in itself, as long as nobody converts the value. Information is lost when timestamps are included. On the night of the switch to winter time, the hour from 2:00 to 3:00 occurs twice, and it is no longer possible to deduce from the value which of the two is meant.
What went wrong in 27.0
Up to and including release 26.0, Invantive UniversalSQL took the value over unchanged, as clock time. In 27.0 the way JSON is read in has been renewed. Exact Online has also been classified as a platform that returns local time. The value was then converted to UTC using the time zone of the computer on which the query runs.
On a computer in the Netherlands, 13 January 00:00 therefore became 12 January 23:00 in winter, and 22:00 in summer. On a computer set to UTC, nothing shifted. The outcome of the same query therefore depended on the computer it ran on.
Impact on the margin per order
In the query, the Sunday of the week is determined with:
sor.sor_orderdate - to_number(to_char(sor.sor_orderdate, 'D'))
That outcome is compared with the dates in the table with purchase prices per week. These dates are taken from the calendar and always fall at midnight. Due to the time offset, the order date no longer fell at midnight, and often even fell on the previous day. As a result, the comparison could not find a purchase price for the previous or following week, meaning the cost price reverted to the standard cost price. This is how the difference in gross margin between 25.0 and 27.0 arose.
Solution
From release 27.0.84 onward, dates and times from Exact Online are again read unchanged as local clock time, as up to and including 26.0. This applies to both the REST and the XML API.
Exact Online also returns a time offset via current/Me (ServerUtcOffset). This was deliberately not used to convert the value back to an actual UTC time, because it is meaningless for this purpose:
- The offset applies to the current moment of the request, not to the moment the value was generated;
- The offset changes with every transition between summer and winter time, whilst an order date may fall on either side of such a transition;
- During the two-hour period of the switch to winter time, the actual time can no longer be determined.
This new release can be downloaded from:

Collection of all current downloads of Invantive Software products. If you require specific versions other than those listed, please contact Invantive Support.
download.invantive.eu
Workaround until the new release is installed 27.0.84
Round every date from Exact Online in the query with round(...) before calculating or comparing with it. For the attached query, this concerns tle.date, sor.orderdate, por.orderdate and sor.sor_orderdate, for example:
round(sor.sor_orderdate) - to_number(to_char(round(sor.sor_orderdate), 'D'))
and
select round(por.orderdate) orderdate
, round(por.orderdate) - to_number(to_char(round(por.orderdate), 'D'))
sun_in_week_date
round rounds a date to the nearest midnight, so that 12 January 23:00 becomes 13 January again. After the new release, a date from Exact Online is again at midnight, and then round changes nothing; the workaround can therefore remain in place.
Do not use trunc: this omits the time and incorrectly returns 12 January.
The week and month (to_char(..., 'YYYYIW') and to_char(..., 'YYYYMM')) and the selection based on the start date may also be incorrect due to the shift. An order placed on Monday 00:00 would otherwise fall into the previous week, and an order placed on the first of the month would fall into the previous month. That is why round is also included in the list above.
Reply 4
This question was automatically closed after 1 week of inactivity. The last answer provided has been marked as the solution.
Please ask a new question in a separate thread if the problem reoccurs. Please include a link to this thread in the new question by pasting its URL into the text.
Reply 2
Given the logic of the algorithm, it is likely that this is because release 27, unlike release 25, calculates with dates in UTC. This is also the cause of:
For example, this formula therefore produces a different result:
por.orderdate - to_number(to_char(por.orderdate, 'D'))
It will be examined whether this should be solved within the report or whether it will be improved in this or a subsequent release with additional functionality.