Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
GopalBh
Contributor II
Contributor II

Calculate percentage in pivot table based max row value

Hi, 

I have a data with pivot table as 

Dimensions:

row - status   

column - date & values

measures

count(status)

status date values
     
     
  count(status) %
Inq created 500  
Inq Closed 10 2%
Inq response 300 60%
Inq conf 200

40%

 

I want to have % column. Here I am calculating % against "Inq created".    i.e (Inq Closed/Inq created) --> (20/500)*100 = 2%

Please help.

Labels (1)
8 Replies
justISO
Specialist
Specialist

Hi, maybe something like this could work? if you put new measure with set analysis always divide from 'Inq created' value:

count(status) / count( total {<status={'Inq created'}>} status)

GopalBh
Contributor II
Contributor II
Author

Hi,

Thank you for that. I get percentage, but not the correct percentage value. In my example:

I have 

Inq Closed: 12

Inq Created: 711

Inq Response: 699

But I get % as 1%, 45% and 44% respectively. Actually % for "Inq Response" should be (699/711)*100 = 98%.

 

justISO
Specialist
Specialist

hmm, I created a little sample like yours:

test_data:
load * inline [
status, data
Inq Created, 1,
Inq Created, 2,
Inq Created, 3
Inq Created, 4,
Inq Created, 5,
Inq Created, 6,
Inq Created, 7,
Inq Closed, 1,
Inq Response, 1,
Inq Response, 2,
Inq Response, 3,
Inq Response, 4,
Inq Response, 5,
Inq Response, 6 ];

and result in pivot table seems ok for me with the same formula I provided before:

justISO_0-1648114254707.png

 

GopalBh
Contributor II
Contributor II
Author

Hi,

Thank you for that. It works when I remove Date from column. Because Date has more than one day day or if I keep data for only one day, then the result is good.

How is there is data for more than one day in the column

brunobertels
Master
Master

Hi 

may be this 

count(status) / count( total {<status={'Inq created'},Date=>} status)

GopalBh
Contributor II
Contributor II
Author

Please see the output in PivotPlease see the output in Pivot

justISO
Specialist
Specialist

try with aggregation per date:

Count(status) / Aggr(nodistinct Count({<status={'Inq Created'}>}status), date)

GopalBh
Contributor II
Contributor II
Author

Hi, Perfect. Thank you very much for the help.