Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Rich5678
Contributor III
Contributor III

Simple Table with Sub-totals

Using Qlik Sense, can you tell me, how to get Sub-totals within a Table.

For example, I have 2 Tables.

Table 1 (in CSV format)

Product,pType
Roses,Flowers
Jasmine,Flowers
Marigold,Flowers
Apples,Fruits
Bananas,Fruits
Grapes,Fruits
Peaches,Fruits
Walnuts,Nuts
Peanuts,Nuts

Table 2 (in CSV format):

Product,Quantity
Roses,20
Jasmine,200
Marigold,50
Apples,24
Bananas,48
Grapes,300
Peaches,36
Walnuts,12
Peanuts,25

Required:
Using above data, I want a Simple Table, where only 2 columns are shown, as below:

Product   Quantity
Roses        20
Jasmine   200
Marigold    50
Flowers     270

Apples        24
Bananas    48
Grapes      300
Peaches     36
Fruits         408
Walnuts     12
Peanuts      25
Nuts             37

I would like to see "Flowers", "Fruits" and "Nuts" in Bold Font

Labels (5)
2 Solutions

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Is your Qlik Sense on-premise or Cloud?

The typical approach is to use a pivot table with a separate field for the pType, giving results like this:

rwunderlich_0-1676338161121.png

Would that meet your needs?  If you absolutely need the two column approach you could combine the two csv files in the load script like this:

Data:
LOAD * Inline [
Product,pType
Roses,Flowers
Jasmine,Flowers
Marigold,Flowers
Apples,Fruits
Bananas,Fruits
Grapes,Fruits
Peaches,Fruits
Walnuts,Nuts
Peanuts,Nuts
]
;

Join (Data)
LOAD *, 0 as TotalRow Inline [
Product,Quantity
Roses,20
Jasmine,200
Marigold,50
Apples,24
Bananas,48
Grapes,300
Peaches,36
Walnuts,12
Peanuts,25
]
;

Concatenate (Data)
LOAD
1 as TotalRow,
pType,
pType as Product,
Sum(Quantity) as Quantity
Resident Data
Group By pType
;

Then use a standard table chart with dimensions:

Product 
Quantity

Sort Product column using "Sort by expression":

=FieldIndex('pType', pType)

I'm not sure how to bold a row in a Sense table, but you could mess with background or text color using an expression like:

=if(TotalRow, LightBlue())

rwunderlich_1-1676339747313.png

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

View solution in original post

vinieme12
Champion III
Champion III

here is an alternative script, to only create multiple associations in Table1 only

 

Table1:
load Product,pType,Product as Product_dim,num(recno(),'#,##0.0') as Product_so inline [
Product,pType
Roses,Flowers
Jasmine,Flowers
Marigold,Flowers
Apples,Fruits
Bananas,Fruits
Grapes,Fruits
Peaches,Fruits
Walnuts,Nuts
Peanuts,Nuts
];
// NoConcatenate
temp_t:
Load pType,max(Product_so)+0.5 as Product_so
Resident Table1
Group by pType;

Left Join (temp_t)
Load Product,pType
Resident Table1;

Concatenate(Table1)
Load Product,pType,pType as Product_dim , Product_so
Resident temp_t;
drop table temp_t;


Table2:
load * inline [
Product,Quantity
Roses,20
Jasmine,200
Marigold,50
Apples,24
Bananas,48
Grapes,300
Peaches,36
Walnuts,12
Peanuts,25
];

 

Then in charts use Product_Dim instead

vinieme12_0-1676358592242.png

background expression

=if(frac(Product_so)=0.5,blue())

 

 

 

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

View solution in original post

2 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Is your Qlik Sense on-premise or Cloud?

The typical approach is to use a pivot table with a separate field for the pType, giving results like this:

rwunderlich_0-1676338161121.png

Would that meet your needs?  If you absolutely need the two column approach you could combine the two csv files in the load script like this:

Data:
LOAD * Inline [
Product,pType
Roses,Flowers
Jasmine,Flowers
Marigold,Flowers
Apples,Fruits
Bananas,Fruits
Grapes,Fruits
Peaches,Fruits
Walnuts,Nuts
Peanuts,Nuts
]
;

Join (Data)
LOAD *, 0 as TotalRow Inline [
Product,Quantity
Roses,20
Jasmine,200
Marigold,50
Apples,24
Bananas,48
Grapes,300
Peaches,36
Walnuts,12
Peanuts,25
]
;

Concatenate (Data)
LOAD
1 as TotalRow,
pType,
pType as Product,
Sum(Quantity) as Quantity
Resident Data
Group By pType
;

Then use a standard table chart with dimensions:

Product 
Quantity

Sort Product column using "Sort by expression":

=FieldIndex('pType', pType)

I'm not sure how to bold a row in a Sense table, but you could mess with background or text color using an expression like:

=if(TotalRow, LightBlue())

rwunderlich_1-1676339747313.png

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

vinieme12
Champion III
Champion III

here is an alternative script, to only create multiple associations in Table1 only

 

Table1:
load Product,pType,Product as Product_dim,num(recno(),'#,##0.0') as Product_so inline [
Product,pType
Roses,Flowers
Jasmine,Flowers
Marigold,Flowers
Apples,Fruits
Bananas,Fruits
Grapes,Fruits
Peaches,Fruits
Walnuts,Nuts
Peanuts,Nuts
];
// NoConcatenate
temp_t:
Load pType,max(Product_so)+0.5 as Product_so
Resident Table1
Group by pType;

Left Join (temp_t)
Load Product,pType
Resident Table1;

Concatenate(Table1)
Load Product,pType,pType as Product_dim , Product_so
Resident temp_t;
drop table temp_t;


Table2:
load * inline [
Product,Quantity
Roses,20
Jasmine,200
Marigold,50
Apples,24
Bananas,48
Grapes,300
Peaches,36
Walnuts,12
Peanuts,25
];

 

Then in charts use Product_Dim instead

vinieme12_0-1676358592242.png

background expression

=if(frac(Product_so)=0.5,blue())

 

 

 

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