Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

how to solve the pivot table problem

Hi,

I have some sample data in pivot table is given below

monthstatusgrandtotal
janlst40
nd85
wn125
FEBlst36
nd87
wn113

i need in given below  format

monthlstndwngrandtotal
jan4030373
feb4535484
mar65455115
grandtotal15011012272

any one please help me..................

10 Replies
JonnyPoole
Former Employee
Former Employee

Here is my solution:

Data:

monthstatusgrandtotal
JANlst40
nd85
wn125
FEBlst36
nd87
wn113

Load Script:

Months:

load Distinct

  rowno() as Record,

  month

FROM

(ooxml, embedded labels, table is Sheet1)

where isnull(month) <> - 1;

left join (Months)

load

  ceil(RecNo()/3) as Record,

  status,

  grandtotal

FROM

(ooxml, embedded labels, table is Sheet1);

Screenshot:

pivot.PNG.png

Not applicable
Author

Thnak you so much  but i need

the pivot table is generated in sheet level(in dashboard)

monthstatusgrandtotal
janlost40
nodecision85
won125
FEBlost36
nodecision87
won113

like this.

after change the data in the given format i required

monthlostnodecisionwongrandtotal
jan4030373
feb4535484
mar65455115
grandtotal15011012272
Not applicable
Author

how to write  scripting after generating the pivot table in dashboard is it possible plz tell me......

JonnyPoole
Former Employee
Former Employee

You can't reverse engineer a pivot table into script.

If your months are reported on the 'middle row' of each block like this:

monthstatusgrandtotal
lst40
jannd85
wn125
lst36
febnd87
wn113

then tweak the script slightly to this:

Months:

load Distinct

  ceil(recno()/3) as Record,

  month

FROM

(ooxml, embedded labels, table is Sheet1)

where isnull(month) <> - 1;

left join (Months)

load

  ceil(RecNo()/3) as Record,

  status,

  grandtotal

FROM

(ooxml, embedded labels, table is Sheet1);

Not applicable
Author

sorry jonathan can't understand.i m taking data from .qvd file. the .qvd file loaded into qlikview  i need to generate the pivot table.  i generate pivot.  the pivot table is  like this.

monthstatusgrandtotal
janlost40
nodecision85
won125
FEBlost36
nodecision87
won113

the grand total column generated after created pivot table not their in before.

but my required pivot table is

monthlostnodecisionwongrandtotal
jan4030373
feb4535484
mar65455115
grandtotal15011012272

how plz tell me.....

JonnyPoole
Former Employee
Former Employee

drag the 'status' field to the columns as below.  Then go to the chart properties / presentation tab, select month and enable 'partial sums' and repeat for status as well.  Please note that the math in your desired output does not reflect the data ...  you need to explain why if the totals in the desired output are indeed correct.

Untitled.png

Not applicable
Author

k Thanks Jonathan in that I need one more column like % column means won/total=%(column). how to add the column to pivot table plz explain me....

JonnyPoole
Former Employee
Former Employee

You can add a 2nd expression on the expression tab with this formula:

= sum(  grandtotal) / sum(  total  grandtotal)

However this will add a % of total for all status'.  Give it a try and see if you like it. If you need it to be more specific then read on:

To only have  '% Won' is a little more involved. One way is as follows:

1. Create a new dimension based on status that adds '% Won' as a status

2. Alter the expression to calculate a % of total won for the '% Won' column

Here is a sample load script with 3 steps.  On the chart, replace 'status' with 'statusforchart' as the dimension, change the sort order of statusforchart to be 'expression and select 'statussort'. then alter the expression to:

if (statusforchart='% Won' , num( sum( {$<status={wn}>} grandtotal) / sum( {$<status={wn}>} total  grandtotal),'#,###.0%') ,num( sum(grandtotal),'#,###,####'))

LOAD SCRIPT:

Months:

LOAD month,

     status,

     grandtotal

FROM

(ooxml, embedded labels, table is Sheet1);

Status:

load Distinct

  status,

  status as statusforchart,

  if (status = 'lost',1, if(status = 'nodecision', 2 , if (status = 'wn',3))) as statussort

Resident Months;

Concatenate (Status)

load

  'wn' as status,

  '% Won' as statusforchart,

  4 as statussort

AutoGenerate 1;

Capture.PNG.png

Not applicable
Author

Hi Jonathan,

Actually  my problem is i have .qvd file data. data the used to generate the pivot table like this 

monthlostnodecisionwongrandtotal
jan4030373
feb4535484
mar65455115
grandtotal15011012272

but i need this type

monthlostnodecisionwongrandtotalRate%
jan4030373won/Grandtotal
feb4535484won/Grandtotal
mar65455115won/Grandtotal
grandtotal15011012272won/Grandtotal

my using the this expression count({<status={'won'}>}[month])/count(status)

it will generate like this but i need only rate% column after the grand total only

monthlost nodecision won grandtotalRate%
grandtotalRate%grandtotalRate%grandtotalRate%
jan40 30 3 73
feb45 35 4 84
mar65 45 5 115
grandtotal150 110 12 272