Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
charles1981
Contributor II
Contributor II

Create a calculated rows in pivot table

Hi, can anyone please help me to achieve the below:

I have one pivot table like below:

Program Market Model Period Dec-19Feb-19Apr-19Jun-19Aug-19Oct-19Sep-19Jan-19Jul-19May-19Mar-19Nov-19F/Yr Total 
P81AustraliaCa 794217199166318985067316375743780487220876070787987931877044926628
Tr 252561900219947304742184722097222581665219967239542440022611268465
Total  104677909938626512898095010978401003068886096037102752103718996551195093
Total Market Industry   104677909938626512898095010978401003068886096037102752103718996551195093
P82AustraliaCa 794007199166318985067316375743780487220876070787987931877044926628
Tr 252011900219947304742184722097222881630219967239542440022611268145
Total  104601909938626512898095010978401003368851096037102752103718996551194773
Total Market Industry   104601909938626512898095010978401003368851096037102752103718996551194773

 

Now I want to create a additional calculated row in the above table to find difference of each month between the programs (first column) as below

Program Market Model Period Dec-19Feb-19Apr-19Jun-19Aug-19Oct-19Sep-19Jan-19Jul-19May-19Mar-19Nov-19F/Yr Total 
P81AustraliaCa 794217199166318985067316375743780487220876070787987931877044926628
Tr 252561900219947304742184722097222581665219967239542440022611268465
Total  104677909938626512898095010978401003068886096037102752103718996551195093
Total Market Industry   104677909938626512898095010978401003068886096037102752103718996551195093
P82AustraliaCa 794007199166318985067316375743780487220876070787987931877044926628
Tr 252011900219947304742184722097222881630219967239542440022611268145
Total  104601909938626512898095010978401003368851096037102752103718996551194773
P81 o/u P82AustraliaCa 2100          
P81 o/u P82AustraliaTr 5500          
P81 o/u P82AustraliaTotal  7600          

like above I want to create calculated row P81 o/u P82 (P81->Australia->Ca - P82->Australia->Ca) for all the months.

 

1 Solution

Accepted Solutions
Sergey_Shuklin
Specialist
Specialist

Hello!

There is a solution. Please, see at this short instace:

First of all you need to load additional table in the script

diff_pivot_rows_pic1.png

After that, write your calculated dimension like this:

diff_pivot_rows_pic3.png

And expression like this:

diff_pivot_rows_pic2.png

This way will calculate sum for P* rows for dim = 1 and difference of P* rows for dim = 2.

View solution in original post

6 Replies
Sergey_Shuklin
Specialist
Specialist

Hello!

There is a solution. Please, see at this short instace:

First of all you need to load additional table in the script

diff_pivot_rows_pic1.png

After that, write your calculated dimension like this:

diff_pivot_rows_pic3.png

And expression like this:

diff_pivot_rows_pic2.png

This way will calculate sum for P* rows for dim = 1 and difference of P* rows for dim = 2.

charles1981
Contributor II
Contributor II
Author

Thank you  so much.

Kejti
Partner - Contributor II
Partner - Contributor II

Hi Sergey!

Do you know is it possible to do that in QS? 

I've added the DIM table and first expression - what gives me a total number. But how and where can I add the second expression? 

 

Thanks in advance!

Sergey_Shuklin
Specialist
Specialist

Hello, Kejti

Yes you can do the same in QS.

You should create dim table as we do in QV:

Sergey_Shuklin_0-1625242068209.png

Then you can create a table:

Sergey_Shuklin_1-1625242132962.png

With dimension:

Sergey_Shuklin_2-1625242162911.png

First value will expand stores, second will be custom calculated.

When you done with dimensions, let's take a look at expressions:

Sergey_Shuklin_3-1625242246730.png

For stores we will simple get sum of sales. But for custom row we use more specific condition - sum only when flag field is equal one.

You should get such result:

Sergey_Shuklin_4-1625242410345.png

If you don't like "-" in the total row, you can handle it with Dimensionality() function:

Sergey_Shuklin_5-1625242506267.png

As you can see, for total row we use some untypical condition as well.

Result table:

Sergey_Shuklin_6-1625242570369.png

 

 

Kejti
Partner - Contributor II
Partner - Contributor II

Thanks @Sergey_Shuklin  it works perfect, but I need to add more than one calculated row. Not sure, if I should create more DIM islands? Or this solution will work just for the one calc. dimension?

Kejti
Partner - Contributor II
Partner - Contributor II

Ok, I've just added more arguments to the Dim island and it works. Thank you very much!!