Order items
Retrieves order items from the "economic" integration. It combines data from the "orders" table and the "customers" table, joining them based on the customer ID. The result is sorted in descending order by date.
- Grain
- See the notes
- Built from
- 2Raw tables
- 1Core
- 1Analytics
- Reads from E-conomic
- customersorders
- Ships as
- Weld and dbt SQL, open source on GitHub
1-- core.economic.order_items
2-- Order items. Retrieves order items from the "economic" integration. It combines
3-- data from the "orders" table and the "customers" table, joining them based on the
4-- customer ID. The result is sorted in descending order by date.
5--
6-- The line ID is the document number and line number joined with a hyphen,
7-- so invoice 12 line 3 and invoice 1 line 23 stay distinct.
8--
9-- From the weld.app template library, corrected. Not reconciled against
10-- e-conomic; check the output against the source before relying on it.
11
12with order_items as ( select date as date ,orderNumber as order_id , concat(cast(orderNumber as string), '-', cast(a.lineNumber as string)) as order_line_id , i.customer_customerNumber as customer_id , orderType as invoice_type , currency , a.lineNumber as line_id , a.description , a.unit ,a.quantity ,a.unitNetPrice as unit_net_price ,a.discountPercentage as discount_percentage ,a.unitCostPrice as unit_cost_price ,a.totalNetAmount as total_net_amount ,a.marginInBaseCurrency as margin_in_base_currency ,a.marginPercentage as margin_percentage ,a.departmentalDistribution as departmental_distribution from {{raw.economic.orders}} i left join unnest (lines) as a ) select c.name , i.* from order_items i left join {{raw.economic.customers}} c on i.customer_id = c.customerNumber order by date descThis model and the 1 it depends on. Deploy them together; refs like {{staging.…}} resolve to the matching folders in Weld, and the dbt view uses source() and ref().
How it counts. And where it stops.
The SQL template named "Order items" is designed for integration with the economic system. This SQL model allows you to retrieve detailed information about order items, including the date, order ID, order line ID, customer ID, invoice type, currency, line ID, description, unit, quantity, unit net price, discount percentage, unit cost price, total net amount, margin in base currency, margin percentage, and departmental distribution. By executing this SQL template, you can gain insights into the order items data, such as analyzing sales trends, identifying top customers, monitoring margins, and tracking departmental distribution. The SQL code retrieves the relevant data from the "economic" database tables, specifically the "orders" and "customers" tables. The result is sorted in descending order based on the date. This SQL template can be useful for businesses using the economic system to manage their orders and customers. It provides a comprehensive view of order items, allowing for analysis and decision-making based on various parameters.
Raw tables it reads
- raw.economic.customers
- raw.economic.orders
More E-conomic models
Put E-conomic in front
of your agents.
Connect E-conomic, deploy the models, and ask questions in Claude, Cursor or ChatGPT. Free for 14 days, no credit card.