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

Announcements
Talend Cloud AWS EU Scheduled Outage: Starting Tues 26 May 21:00 CEST with expected completion Wed 27 May 01:00 CEST
cancel
Showing results for 
Search instead for 
Did you mean: 
Maury_19
Partner - Contributor III
Partner - Contributor III

Scostamento Mesi in Anni diversi

Ho una pivot con colonne Anni suddivisi in Mesi in #Qlik Sense

Come posso calcolare lo scostamento tra 2 mesi di anni diversi? (p.es. Maggio2024 vs maggio 2023).

Utilizzando Before/After mi confronta due mesi successivi (p.es. Maggio 2024 vs Aprile 2024)

Grazie, Maurizio

Labels (1)
1 Solution

Accepted Solutions
Qrishna
Master
Master

In a pivot table, do this:

Dim: MonthName, Year (Pivoted as header)
Measure1: cy = sum(Sales)
Measure2: py_samemonth = if(not isnull(after(sum(Sales))), after(sum(Sales)), 0)
Measure3: diff = cy-py_samemonth

i492528 - Months Deviation in Different Years - Prior Year Same Mont.PNG

if you change the order of the year use before() function, as needed

View solution in original post

5 Replies
sbaro_bd
Creator III
Creator III

Ciao @Maury_19 ,

Usa la funzione AddMonths(). Ti consente di ottenere il periodo di ritardo in base al parametro di passaggio utilizzato.
Otterrai ad esempio un'espressione come questa: SUM({<MonthYear={"$(=AddMonths(MonthYear,-12))"}>} Measure).

Segui il link per la guida di Qlik: https://help.qlik.com/en-US/sense/May2024/Subsystems/Hub/Content/Sense_Hub/Scripting/DateAndTimeFunc...

Saluti.

Qrishna
Master
Master

In a pivot table, do this:

Dim: MonthName, Year (Pivoted as header)
Measure1: cy = sum(Sales)
Measure2: py_samemonth = if(not isnull(after(sum(Sales))), after(sum(Sales)), 0)
Measure3: diff = cy-py_samemonth

i492528 - Months Deviation in Different Years - Prior Year Same Mont.PNG

if you change the order of the year use before() function, as needed

Maury_19
Partner - Contributor III
Partner - Contributor III
Author

Ho seguito le tue indicazioni però (come si vede da tabella allegata) nella pivot (che evidenzia Anni e Mesi) lo scostamento viene fatto sul mese precedente dello stesso anno e non sullo stesso mese dell'anno precedente...

Grazie, Maurizio

 

 

Maury_19
Partner - Contributor III
Partner - Contributor III
Author

ma il campo MonthYear è un campo importato oppure posso costruirlo in Qlik concatenando Mese e Anno?

Grazie, Maurizio

sbaro_bd
Creator III
Creator III

No, era solo a scopo illustrativo. Il metodo @Qrishna  è una buona idea da seguire.