Omniscope Custom Blocks › Preparation/Top-N-With-Other

Top N With Other

Keeps the top N items per group by value and rolls the rest into an Other row, with ranks, shares and cumulative shares.

Preparation › Aggregate Python visokio-agents

Open the demo in Omniscope Download demo.ioz Sample data: regional-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

Keep the top N items per group and roll the rest into Other, with ranks and shares, so every chart and table stays readable.

Python · pandas, numpy · nothing extra to install

The problem it solves

Twenty slices in a pie chart, or a bar chart with a long tail of tiny bars, hide the message. The usual fix, top N plus Other, takes sorting, sampling, summing the rest and appending it, per group.

This block does it in one step per group, carries other values (units, margin) along, and adds rank, share and cumulative share to every row.

How it works

What goes in

Regional sales

Synthetic sales lines for 20 products in four regions.

Region Product Revenue (GBP) Units
North Product A 1736.22 199
North Product B 13436.14 109
North Product C 7073.64 90
North Product C 3622.18 80
North Product C 7501.73 40
North Product D 4344.4 34

168 rows in the sample file.

The options

Option Demo setting What it does
Item field Product For example Product or Supplier.
Rank by value Revenue (GBP) The number items are ranked on, such as revenue.
Per group (optional) Region For example Region.
Other values to carry (optional) Units Other numbers to total into the Other row alongside the ranking value.
Top N 5 0 = no limit (use the minimum share).
Add an Other row On Adds a row totalling the items outside the top N.

What comes out

Top five and Other (North and South)

Region Product Rank Revenue (GBP) Units Share Of Group Cumulative Share Items Included Is Other
North Product F 1 414,095.41 252 0.347 0.347 1 No
North Product R 2 300,898.11 223 0.252 0.598 1 No
North Product O 3 142,110.74 27 0.119 0.717 1 No
North Product P 4 63,968.72 161 0.054 0.771 1 No
North Product Q 5 51,547.07 225 0.043 0.814 1 No
North Other 6 222,294.09 3,014 0.186 1 15 Yes
South Product F 1 217,782.82 244 0.278 0.278 1 No
South Product R 2 134,686.53 39 0.172 0.45 1 No
South Product O 3 126,235.37 15 0.161 0.612 1 No
South Product P 4 80,945.37 326 0.103 0.715 1 No
South Product N 5 33,761.30 300 0.043 0.758 1 No
South Other 6 189,383.08 3,411 0.242 1 15 Yes
A readable chart: five products and one Other slice (synthetic data).
A readable chart: five products and one Other slice (synthetic data).

A readable chart: five products and one Other slice (synthetic data).

How much each region's long tail holds.
How much each region's long tail holds.

How much each region's long tail holds.

Where it pays off

Retail: Product mix charts

Top products per store or region with the rest as Other, for dashboards and board packs.

Procurement: Spend by supplier

Top suppliers per category plus Other, or every supplier above 2% of spend.

Marketing: Channels and campaigns

Top traffic sources per site with the long tail grouped.

Finance: Customer revenue tables

Largest customers per business unit and the rest, with cumulative share.

Use cases describe typical scenarios and are illustrative.

Why do this in Omniscope

How it fits into an Omniscope workflow

Data → Top N With Other → Report (pie, bar, table)

Run just before the chart; ABC Classification and Concentration Measures give the analysis behind the long tail.

Sort by Rank so Other always sits last.

In one step

Top N per group with an Other row, shares and ranks.

Try it

  1. Open the demo project (demo.iox on the demo server, or import demo.ioz from this folder): synthetic sales of 20 products in four regions.
  2. The question: can we show product mix per region without a 20-slice pie?
  3. Run the block: top five per region plus Other.
  4. Look at the chart, then switch to a minimum share of 5% instead of a fixed five.
  5. Note that Units are summed into Other too.

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

Run on an Omniscope server, the demo workflow finished without errors (24 records in Top N with Other). Automated tests also cover normal data, empty input, wrong types and large input.

Reference

Fields it reads

NameTypeWhat it does
Item fieldFieldFor example Product or Supplier.
Rank by valueFieldThe number items are ranked on, such as revenue.
Per group (optional)FieldsFor example Region.
Other values to carry (optional)FieldsOther numbers to total into the Other row alongside the ranking value.

Options

NameTypeWhat it does
Top NWhole number0 = no limit (use the minimum share).
Minimum share of groupNumberFor example 0.02; 0 = none.
Add an Other rowYes / noAdds a row totalling the items outside the top N.
Label for OtherText

Outputs

OutputWhat it holds
Top NPer group: kept items and an Other row, with rank, values, share of group, cumulative share, items included.