Omniscope Custom Blocks › Preparation/Multi-Row-Formula

Multi-Row Formula

Window calculations across rows within groups: previous / next value, change, % change, running total, rolling mean / sum / min / max over rows or days, rank and share of group.

Preparation › Formula Python visokio-agents

Open the demo in Omniscope Download demo.ioz Sample data: store-daily-sales.csv Source on GitHub

Items tagged visokio-agents are community examples built by Visokio's agents, to extend Omniscope's core blocks and views with popular, specialist and more unusual use cases, and to show what anyone, people or agents, can build on Omniscope. They are tested by automated tests and were run on a real Omniscope server. They were not reviewed by Omniscope's core team, so they are not on a par with the core blocks and views, which have years of manual, functional and unit tests behind them. About

Omniscope custom block · Preparation

Previous value, change, running totals, rolling averages and ranks, per group and in date order: the calculations that need more than one row, in one block.

Python · pandas, numpy · nothing extra to install

The problem it solves

Most business questions compare a row with its neighbours: how did sales change since yesterday?, what is the 7-day average?, what is the running total this month?, which was the best day per store?. Formulas work one row at a time, so these need either self-joins on shifted copies of the data or special functions that do not restart per group.

Multi-Row Formula does them directly: choose value fields, a group (store, customer, product) and an order (date), then tick the calculations. Rolling windows can count rows or calendar days, so a store closed for two days does not distort its 7-day average.

How it works

What goes in

Daily sales for three stores

Seven weeks of synthetic daily sales. Glasgow was closed on 14 and 15 September for a refit, so those dates are missing.

Store Date Sales Transactions
Leeds 2025-09-01 2093.89 53
Leeds 2025-09-02 1867.65 67
Leeds 2025-09-03 1748.7 70
Leeds 2025-09-04 1527.23 70
Leeds 2025-09-05 1702.22 95
Leeds 2025-09-06 2523.37 93
Leeds 2025-09-07 2432.33 90
Leeds 2025-09-08 1694.2 69

145 rows in the sample file.

The options

Option Demo setting What it does
Value fields Sales Fields to calculate on. Previous / next work for any field; the other calculations need numbers.
Group by (optional) Store Calculations restart for each combination of these fields, for example Store or Customer.
Order by Date Order of rows within each group, usually a date. For rolling windows in days choose exactly one date field.
% change vs previous On As a fraction: 0.05 means up 5%.
Rolling mean On Average over the rolling window.
Rolling window counts Days (uses the date in Order by) Whether the window counts rows or days of the date in Order by.
Running total On Cumulative sum within each group.
Rolling window size 7 Rows or days in each rolling window.
Rows back / forward 1 For previous, next and change: 1 compares with the row just before; 7 with daily data compares with the same weekday last week.

What comes out

Output: Glasgow around its closure

On 16 September the 7-day mean covers 10 to 16 September: five trading days, not the last seven rows.

Store Date Sales Sales Previous Sales Change Sales % Change Sales Running Total Sales Rolling Mean (7 days)
Glasgow 2025-09-10 969.95 1,008.47 -38.52 -0.0382 10,213.37 1,029.04
Glasgow 2025-09-11 977.37 969.95 7.42 0.0076 11,190.74 1,029.18
Glasgow 2025-09-12 925.75 977.37 -51.62 -0.0528 12,116.49 1,041.28
Glasgow 2025-09-13 1,114.14 925.75 188.39 0.2035 13,230.63 1,039.82
Glasgow 2025-09-16 910.48 1,114.14 -203.66 -0.1828 14,141.11 979.54
Glasgow 2025-09-17 1,113.49 910.48 203.01 0.223 15,254.60 1,008.25
Glasgow 2025-09-18 1,026.36 1,113.49 -87.13 -0.0782 16,280.96 1,018.04
Glasgow 2025-09-19 933.12 1,026.36 -93.24 -0.0908 17,214.08 1,019.52
Glasgow 2025-09-20 1,329 933.12 395.88 0.4243 18,543.08 1,062.49
Glasgow 2025-09-21 1,355.55 1,329 26.55 0.02 19,898.63 1,111.33
Daily sales are noisy, with weekend peaks; the 7-day rolling mean shows the underlying trend (synthetic data).
Daily sales are noisy, with weekend peaks; the 7-day rolling mean shows the underlying trend (synthetic data).

Daily sales are noisy, with weekend peaks; the 7-day rolling mean shows the underlying trend (synthetic data).

Running total per store, restarting for each group.
Running total per store, restarting for each group.

Running total per store, restarting for each group.

Where it pays off

Retail: Trading performance by store

Day-on-day and week-on-week change, 7-day and 28-day rolling averages and best-day ranks per store, feeding a daily trading dashboard.

Financial services: Account balances and movements

Running balances from transaction lists, change since last statement and days-since-previous-transaction flags for dormancy and fraud rules.

Manufacturing and IoT: Sensor smoothing and drift

Rolling mean, min and max per machine over the last N readings or N days to smooth noise and spot drift before a failure.

Marketing and e-commerce: Customer journeys

Previous and next event per customer, time between orders and order number per customer, ready for repeat-purchase and churn analysis.

Use cases describe typical scenarios and are illustrative.

Why do this in Omniscope

How it fits into an Omniscope workflow

Sales (Database / File) → Multi-Row Formula → Record filter → Report

Place it after the data is at the grain you want (aggregate first if needed, for example to daily totals per store).

Downstream, filter on the new fields (for example Sales % Change below -0.2 to flag sharp drops) or chart the rolling mean next to the raw values in a Report.

In one step

The common multi-row calculations are tick boxes here, so there is nothing to type. For a stateful custom expression (a value that depends on the previous row's result), Omniscope's formulas or a custom block remain the route.

Try it

  1. Open the demo project (demo.iox on the demo server, or import demo.ioz from this folder): daily sales for three stores. The question: how do we see the trend through the weekend spikes?
  2. Open the Multi-Row Formula block: value Sales, group by Store, order by Date, then tick previous value, change, % change, running total and rolling mean over 7 days.
  3. Run it and look at the output for Glasgow around 14 September: the store was closed, and the 7-day mean uses the five days that exist rather than blindly the last seven rows.
  4. Look at the line chart: daily sales against the rolling mean. The trend is much easier to read.
  5. Previous value, change, running total and rolling mean come from one block with tick boxes, with no separate sort or running-total steps.

Running in Omniscope

Omniscope workflow
Omniscope workflow

The demo project's workflow: the sample data, the block, and a Validate data check on its output.

Language and libraries

Python. It uses pandas and numpy.

pandas and numpy are part of Omniscope's Docker Python image, and the block was run in both host mode and Docker mode on an Omniscope server, with the same results. It needs nothing else installed.

Tested

The demo workflow runs without errors on an Omniscope server and produces 145 records in Result. Its automated tests cover normal data, empty input, wrong types and large input.

Reference

Fields it reads

NameTypeWhat it does
Value fieldsFieldsFields to calculate on. Previous / next work for any field; the other calculations need numbers.
Group by (optional)FieldsCalculations restart for each combination of these fields, for example Store or Customer.
Order byFieldsOrder of rows within each group, usually a date. For rolling windows in days choose exactly one date field.

Options

NameTypeWhat it does
Previous valueYes / no
Next valueYes / no
Change vs previousYes / no
% change vs previousYes / noAs a fraction: 0.05 means up 5%.
Running totalYes / noCumulative sum within each group.
Rolling meanYes / noAverage over the rolling window.
Rolling sumYes / no
Rolling minimumYes / no
Rolling maximumYes / no
Rank in groupYes / no1 = highest value in the group; ties share the lower rank.
Share of group totalYes / no
Row number in groupYes / no
Rows back / forwardWhole numberFor previous, next and change: 1 compares with the row just before; 7 with daily data compares with the same weekday last week.
Rolling window sizeWhole numberRows or days in each rolling window.
Rolling window countsChoiceWhether the window counts rows or days of the date in Order by.
Only when the window is fullYes / noLeave rolling values empty until a full window of rows (or days) is available.
Order descendingYes / noTick to process newest first.
Keep input row orderYes / noUntick to output rows sorted by group and order fields.

Outputs

OutputWhat it holds
ResultThe input with the new calculated fields.