Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
aresb
Creator
Creator

How to insert CY and PY in the same pivot table

Hi everyone, i'm trying to reproduce this table from an old BI tool

aresb_0-1668432715685.png

So in qlik, i created a pivot table and i've added into column the dimension 'CY/PY' in this way

=Valuelist('CY', 'PY')

and i've built the measure in this way 

=

if(ValueList('CY','PY') = 'CY',
count(distinct(({<cod_year_month= {">=$(=min(cod_year_month))<=$(=max(cod_year_month))"}> }MY_MEASURE)))
,count(distinct(({<cod_year_month= {">=$(=min((DATE(addmonths(date#(cod_year_month,'YYYYMM'),-12),'YYYYMM'))))<=$(=max((DATE(addmonths(date#(cod_year_month,'YYYYMM'),-12),'YYYYMM'))))"}> }MY_MEASURE))))

which i supposed is correct.

The main problem is that i can't let this work and i have the same measure in CY and PY.

aresb_1-1668433168008.png

 

What am i doing wrong ?

 

Labels (3)
1 Solution

Accepted Solutions
rubenmarin

Hi, try setting the Date outside the min() and max(), and the min() max() as the first function on the field:

{">=$(=Date(addmonths(date#(min(cod_year_month),'YYYYMM'),-12),'YYYYMM'))<=$(=Date(addmonths(date#(max(cod_year_month),'YYYYMM'),-12)),'YYYYMM'))"}

 

View solution in original post

4 Replies
rubenmarin

Hi, try setting the Date outside the min() and max(), and the min() max() as the first function on the field:

{">=$(=Date(addmonths(date#(min(cod_year_month),'YYYYMM'),-12),'YYYYMM'))<=$(=Date(addmonths(date#(max(cod_year_month),'YYYYMM'),-12)),'YYYYMM'))"}

 

aresb
Creator
Creator
Author

Thx for responding,

now i've this set expression 

aresb_0-1668438160295.png

which recognize correctly year and month as a date for PY, but still replicate the kpi along the table

aresb_1-1668438306254.png

i can't understand what im doing wrong

 

rubenmarin

Hi, it seems ok, if you can upload a sample with some dummy, scrambled or partioned data I could make some tests to check dthe expression needed.

vinieme12
Champion III
Champion III

Try using a Dummy Dimension instead

 

DummyDim:

Load Dual(Dim,so_Dim) as Dim

Load * Inline [

Dim,so_Dim

CY,1

PY,2

];

 

Then in pivot table measures use

 

=Pick(Dim,
//CY-1
,count(distinct({<cod_year_month= {">=$(=min(cod_year_month))<=$(=max(cod_year_month))"}> }MY_MEASURE)
//PY-2
,count(distinct {<cod_year_month = {">=$(=Date(addmonths(date#(min(cod_year_month),'YYYYMM'),-12),'YYYYMM'))<=$(=Date(addmonths(date#(max(cod_year_month),'YYYYMM'),-12)),'YYYYMM'))"} >} MY_MEASURE)
)

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.