Referencing Input Data¶
The page Declaring Input Data explains how to import data in your Kalix model. Here’s a reminder:
Each CSV file should have a date/timestamp column as the first column, followed by one or more data columns:
Referencing Data in Expressions¶
Once imported, you can reference any column using the data.* namespace in dynamic expressions. Kalix provides two ways to reference columns:
By Column Name¶
By Column Index¶
Column indices start at 1 (the first data column after the date column).
Example: For climate.csv with columns Date, Rainfall, Evaporation:
- data.climate_csv.by_name.rainfall - references the Rainfall column
- data.climate_csv.by_index.1 - also references the Rainfall column
- data.climate_csv.by_index.2 - references the Evaporation column
Name Sanitisation¶
Kalix sanitises filenames and column names to ensure valid references:
-
Lowercase conversion - all names become lowercase
-
Special character replacement - characters other than
a-z,0-9, and_are replaced with underscores
| Original | Sanitised |
|---|---|
Climate-Data.csv |
climate_data_csv |
Flow (ML/d) |
flow__ml_d_ |
Station_001 |
station_001 |
This means references are case-insensitive - data.climate_csv.by_name.Rainfall and data.climate_csv.by_name.rainfall both work.
Temporal Offset Syntax¶
You can access values from previous or future timesteps using offset syntax:
-
Negative offset = past values (e.g.,
1= yesterday) -
Zero offset = current timestep
-
Positive offset = future values (e.g.,
+1= tomorrow)
The default_value is returned when the offset goes outside the available data range.
Examples:
# Yesterday's rainfall (default to 0 if at start of data)
data.climate_csv.by_name.rainfall[-1, 0.0]
# Tomorrow's forecast demand (forward lookup)
data.forecast_csv.by_name.demand[1, 20.0]
# Calculate change from yesterday
data.climate_csv.by_name.rainfall - data.climate_csv.by_name.rainfall[-1, 0.0]
Note: Forward lookups (positive offsets) only work for data.* references where data is pre-loaded. They cannot be used with node.* references since future model outputs haven’t been computed yet.
Using Data in Node Parameters¶
Reference data in any node parameter that accepts dynamic expressions: