Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
laura_1
Partner - Contributor III
Partner - Contributor III

Comparison to PY

Hi, 

I'd like to create a line chart with Year-Month as  a dimension and the difference between PY and current year sales as a measure, so for example if we have the following dataset:

LOAD * INLINE
[date, year, sales
2019-01, 2019, 150
2019-02, 2019, 200
2019-03, 2019, 550
2018-01, 2018, 200
2018-02, 2018, 400
2018-03, 2018, 300
];

I'd like the chart to display: 

2019-01:  -50

2019-02: -200

2019-03: 250

Is there a way to achieve this? 

1 Reply
StarinieriG
Partner - Specialist
Partner - Specialist

Hi,

 

you could try to solve it inside the script:

 

TABLE:
LOAD *,
Date(MakeDate(year-1,Right(date,2)),'YYYY-MM') AS date_p,
;
LOAD * INLINE
[date, year, sales
2019-01, 2019, 150
2019-02, 2019, 200
2019-03, 2019, 550
2018-01, 2018, 200
2018-02, 2018, 400
2018-03, 2018, 300
];


Left Join (TABLE)
LOAD
date AS date_p,
sales AS sales_p
Resident TABLE;

 

After that, you could use this expression:

sum(sales)-sum(sales_p)

 sum({<year={'$(=Max(year))'}>}sales)-sum(sales_p) ---> if you want to see only last year