Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Shahzad_Ahsan
Creator III
Creator III

How to make calculation in pivot table

Hi

I have pivot table like below in qlik sense. where "Name" is as dimension and Month-Year as Column and the numbers are in measures.

NameJan-19Feb-19Mar-19Apr-19
A100503665
B20021572574
C3006954885
D4002477798

 

I need to calculate the below data on behalf of above table.

Here, the condition goes like this, Every column is divided by "Apr-19" column

Eg: 100/65=1.54

CategoryJan-19Feb-19Mar-19Apr-19
11.540.770.551
22.7029.150.341
33.538.180.561
44.082.520.791

 

Problem: when I am dividing Jan-19/Apr-19,  it always returns 0. 

Labels (1)
1 Solution

Accepted Solutions
sunny_talwar

Try this

Sum(Amount)/Sum(TOTAL <Bkt, Dpd> {<[Month-Year] = {"$(=Date(Max([Month-Year])))"}>} Amount)

But before you try this for your sample, change the script for the second table to this

Table2:
LOAD Month,
If(date(date#(Month, 'MMM-YYYY'), 'MM/DD/YYYY') >= AddMonths(Today(), -14), date(date#(Month, 'MMM-YYYY'))) as [Month-Year]
Resident Table1;

View solution in original post

19 Replies
Shahzad_Ahsan
Creator III
Creator III
Author

Please find the attached sample qvf file.

JordyWegman
Partner - Master
Partner - Master

Hi Shahzad,

You have to force Qlik to divide by April. Do this by using set analysis. See the following:

Sum(YourAmountfield) / Sum({$< YourYearMonthField = {'Apr-19'}>} YourAmountField)

To make it more reliable, you should create a variable with the last complete month and put this $(variable) in 'Apr-19' in the set analysis.

Jordy

Climber

Work smarter, not harder
Shahzad_Ahsan
Creator III
Creator III
Author

Hi @JordyWegman 

Thanks for your response.

I have already tried this one , but not working

Please find the attached qvf and check the 2nd pivot table.

I am trying to divide the total amount by Mar-2019. All returns 0 and the last column returns 1, that means  the expression below is returning 0 for all accept Mar-2019

Sum({$< YourYearMonthField = {'Apr-19'}>} YourAmountField)

  

sunny_talwar

Try this

Sum(Amount)/Sum(TOTAL <Bkt, Dpd> {<[Month-Year] = {"$(=Date(Max([Month-Year])))"}>} Amount)

But before you try this for your sample, change the script for the second table to this

Table2:
LOAD Month,
If(date(date#(Month, 'MMM-YYYY'), 'MM/DD/YYYY') >= AddMonths(Today(), -14), date(date#(Month, 'MMM-YYYY'))) as [Month-Year]
Resident Table1;

Shahzad_Ahsan
Creator III
Creator III
Author

Hi @sunny_talwar 

Thanks for your response. 

Your suggestion is working fine with Max. But suppose I have to divide by a particular column, that means,(Jan-2018) which is not on the pivot table, it returns 0 

I am showing only last 1 year data in the table.

 

sunny_talwar

I guess you already have your set analysis figured out, right? All you need is to add TOTAL <Bkt, Dpd> in your expression to make it repeat the Jan-2018 value for other Months

sunny_talwar

Something like this

Sum(Amount)/Sum(TOTAL <Bkt, Dpd> {<[Month-Year] = {"Jan-2018"}>} Amount)

Shahzad_Ahsan
Creator III
Creator III
Author

I think I am unable to explain

What I am trying to say is, the below expression is returning 0.  because, Jan-2018 is not in the pivot table column but is available in the data.

Sum(TOTAL <Bkt, Dpd> {<[Month-Year] = {"Jan-2018"}>} Amount)

 

Shahzad_Ahsan
Creator III
Creator III
Author

The below expression which you sent before is working fine.

Sum(Amount)/Sum(TOTAL <Bkt, Dpd> {<[Month-Year] = {"$(=Date(Max([Month-Year])))"}>} Amount)