Question

# Is there a way to have column totals, but only for the top 5 rows?

• 2 replies
• 344 views

• Member
• 3 replies

I have a table with Margin split by Product Type, i would like to show this as a single value visualization, and compare the total margin for the Top 5 to total margin for the rest.

I have tried using the following codes which haven’t worked. If anyone has any ideas/ solutions it would be greatly appreciated 🙂

Attempt 1

\${booking_analysis.margin:total}

(this one uses a row limit of 5)

Attempt 2

\${booking_analysis.margin:total}-offset(\${booking_analysis.margin},5)

### 2 replies

Fantastic! This was exactly what i needed, thanks so much for your help 🙂

Hi @clf333,

If I get it right, you have one column, ordering the margin from high to low, and want to compare the sum of the first five margins to the rest in the same column?

I think a table calculation as below would help with the first part.

``````sum(
if(
row()<=5
, \${booking_analysis.margin}
, 0
)
)
``````

This will only sum the values of the first 5 rows, and add 0’s for the rest.

You could then have another Table Calculation with

``````\${booking_analysis.margin:total} - \${the_first_calculation}
``````

Don’t forget to hide all other measures if you want to show both table calculations in the Single Value visualisation.

I really hope this helps 🙂

Daan