Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
rougeherring
Contributor III
Contributor III

Grouping Columns in Pivot Table - Qlik Sense

In Qlik Sense using a pivot table, how can I add a row header for measures. For example, Tires, Tire Fix need to be grouped as Wheel Shop. Engine Work, Oil, Transmission need to be grouped as Engine Shop. Dent, Scratch as auto body. How can I group them in the Pivot table? The data loaded into Qlik Sense looks exactly as shown below. 

 TiresTire FixEngine WorkOil ChangeTransmissionDentScratch
Max Auto4406787
Jim's Auto56020804
Tim's Engine Works46455210
Sam's Full Service055361220

 

I have seen recommendations to create an inline table with the field names the placement is not working so I'm at a loss. 

Labels (1)
1 Solution

Accepted Solutions
Lisa_P
Employee
Employee

Use a crosstable to unpivot the data as below:

AutoData:
CROSSTABLE ([Service],[Amount],1)
LOAD * INLINE
[
Autoshop,Tires,Tire Fix,Engine Work,Oil Change,Transmission,Dent,Scratch
Max Auto,4,4,0,6,7,8,7
Jim's Auto,5,6,0,20,8,0,4
Tim's Engine Works,4,6,4,55,2,1,0
Sam's Full Service,0,5,5,36,12,2,0
](delimiter is ',');

[Groups]:
LOAD * INLINE
[
Service,Group
Tires,Wheel Shop
Tire Fix,Wheel Shop
Engine Work,Engine Shop
Oil Change,Engine Shop
Transmission,Engine Shop
Dent,Auto Body
Scratch,Auto Body
](delimiter is ',');

View solution in original post

8 Replies
Lisa_P
Employee
Employee

I created another table as inline table as per below:

inlineservices.PNG

 with resulting pivot table

pivotgroup.PNG

 

rougeherring
Contributor III
Contributor III
Author

With the addition of the inline table, how did you make the service data relate to the name of a field? This is exactly what I need but I'm missing the step between the images. 

Lisa_P
Employee
Employee

Can you show a screenshot of your data model viewer to see the name of your fields

rougeherring
Contributor III
Contributor III
Author

AutoData:
Load * Inline [
Autoshop, Tires, Tire Fixes, Engine Work, Oil Changes, Transmissions, Dent Fixes, Scratches
Max's Auto,4,4,0,6,7,8,7
Jim's Auto,5,6,0,20,8,0,4
Tim's Engine Works,4,6,4,55,2,1,0
Sam's Full Service,0,5,5,36,12,2,0
];

rougeherring_0-1595554931996.png

rougeherring_1-1595555021324.png

The dataset is exactly like this with 100,000 unique locations, each with a single record. 

Lisa_P
Employee
Employee

Use a crosstable to unpivot the data as below:

AutoData:
CROSSTABLE ([Service],[Amount],1)
LOAD * INLINE
[
Autoshop,Tires,Tire Fix,Engine Work,Oil Change,Transmission,Dent,Scratch
Max Auto,4,4,0,6,7,8,7
Jim's Auto,5,6,0,20,8,0,4
Tim's Engine Works,4,6,4,55,2,1,0
Sam's Full Service,0,5,5,36,12,2,0
](delimiter is ',');

[Groups]:
LOAD * INLINE
[
Service,Group
Tires,Wheel Shop
Tire Fix,Wheel Shop
Engine Work,Engine Shop
Oil Change,Engine Shop
Transmission,Engine Shop
Dent,Auto Body
Scratch,Auto Body
](delimiter is ',');

Mahamed_Qlik
Specialist
Specialist

what if ,4,4,0,6,7,8,7 are calculated.
Here you have directly pass hardcode values...what if they are calcualting...?

sharmi1990
Contributor
Contributor

@Lisa_P  Any updates to the question above?What if the values are calculated and not hard coded?

markuskoessler
Contributor II
Contributor II

you could do something like this, within you meassure:

if(Service='Dent',1+1,
if(Service='Scratch',1+2,
if(Service='Engine Work',1+3,
if(Service='Oil Change',1+4,
if(Service='Transmission',1+5,
if(Service='Tire Fix',1+6,
if(Service='Tires',1+7
)))))))