Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
aresb
Creator
Creator

How to implement CY and PY in the same row

Hi everyone,

I'm trying to implement a simple set analysis where the user choose a year and the table should appear like this:

aresb_2-1675265046510.png

 

However, when i implement the below set expression and selecting year 2022 as filter i have this, 

 

SUM({$<cod_year={$(=MAX(cod_year)-1)}>}Measures)

 

i have this results:

aresb_3-1675265134570.png

Is there a way to achieve the result in the first image?

Even via data load editor

 

 

 

 

Labels (1)
3 Replies
QFabian
MVP
MVP

Hi @aresb you can try creating a chart table with 3 expressions, no dimensions.

Please check if this example works for you.

 

Script:

Load * INLINE [
cod_year, Measures
2022, 3000
2021, 5000
];

exit script;

chart

QFabian_0-1675268095935.png

Year = only(cod_year)

Measures CY = SUM(Measures)

Measures PY =  SUM({$<cod_year={$(=MAX(cod_year)-1)}>}Measures)

 

Greetings!! Fabián Quezada (QFabian)
did it work for you? give like and mark the solution as accepted.
vinieme12
Champion III
Champion III

As below

 

Dimension

= cod_year

Measure

CY = sum({<cod_year={"$(=MAx(cod_year))"}>}Measures)

PY = sum(aggr(sum({<cod_year={"$(=MAx(cod_year)-1)"}>} TOTAL Measures),cod_year))

 

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

Hi

i 've solved this way  in the data load editor

 

Measure_CY:
LOAD
    "Year",
    "Month",
    Measures as Measure_CY,
    Date#("Year" & "Month",'YYYYMM') as id_date,
    Date#("Year" & "Month"+100,'YYYYMM') as id_date_1
    
FROM [lib://m/Misura PY qlik.xlsx]
(ooxml, embedded labels, table is Foglio1);

NoConcatenate[Measure_CY]:

Load

Date#(id_date_1,'YYYYMM') as id_date,
Measure_CY as Measure_PY
Resident Measure_CY
WHERE YEAR(Date(id_date_1,'YYYYMM')) <= YEAR(now());
drop Field id_date_1





 

which give me this

 

aresb_0-1676469612325.png