Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
styleofme
Contributor
Contributor

How to get a subtotal line in my table?

Hello,

I have this simple table, with a dimension "Customer" and 2 measures : https://imgur.com/a/GwhbM2U 

My Customer dimension is set with a limitation of top 10 and with "Others" (out of top 10) displayed. I would like to add the subtotal of my 2 measures for my top 10 customers in my table. The goal would be to have this subtotal row between the top 10 Customer rows and my "Others" row.

Do you know if this is possible? I could also make use of a pivot table if needed.

Thank you in advance!

Labels (2)
4 Replies
Ravi_Nagmal
Contributor III
Contributor III

@styleofme can you share what is ticked in below presentation setting

Ravi_Nagmal_0-1703667157041.png

 

Aditya_Chitale
Specialist
Specialist

@styleofme ,

You can achieve this using script. You cannot do this on frontend directly.

For this create a resident load from Fact table and use recno() with order by clause to load only top N records in resident table. Now create an additional field as "Sort" in both resident and fact tables and assign it a value in both tables. Note that the value of this field should be greater in resident table that fact table.

Finally in frontend table chart use this field to achieve desired sort order.

You can refer below screenshot of sample script and output (I have sub-totaled top 3 rows hence recno()<=3) :

Aditya_Chitale_1-1703674081574.png

Output:

Aditya_Chitale_2-1703674270439.png

 

Regards,

Aditya

 

vinieme12
Champion III
Champion III

A Small inline table will do the trick

vinieme12_2-1703732696284.png

 

 

 

example

 

 

//Sample raw data 
data:
Load *,recno() as Sales inline [
Cust
A
B
C
D
E
F
G
H
I
J
K
L
M
N
];

//Inline table to group subtotal and Others
Temp:
Load * inline [
dim,so_dim
Customer,1
SubTotal,2
Others,3
];

 

 

 

Raw Data

vinieme12_0-1703732514681.png

 

IN a Table Chart

Dimension:

=pick(so_dim,Cust,dim,dim)

 

Measure:

=Pick(so_dim
,aggr(if(rank(Sum(Sales),4,2)<=10,sum(Sales)),Cust)   // Expression for Top 10 Customers
,sum(total aggr( if(rank(Sum(Sales),4,2)<=10,sum(Sales)),Cust))   // Expression for Subtotal of Top 10 Customers
,sum(total aggr( if(rank(Sum(Sales),4,2)>10,sum(Sales)),Cust))   // Expression for SubTotal of Customers ranking beyond 10
)

 

vinieme12_0-1703732958066.png

 

 

 

 

 

 

 

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
Ahidhar
Creator III
Creator III

try it in Pivot table like this

tab1:
load Customer,sum(Sales) as sales group by Customer;
load * inline
[
Customer,Sales
1,10
2,20
3,30
4,40
5,50
6,60
7,70
8,80
9,90
10,100
11,110
];
NoConcatenate
tab2:
load *,
if(recno()<10,'Top10','Others') as status
resident tab1 order by sales desc;drop table tab1;

Ahidhar_0-1703757027684.png