Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I have to create a straight table in which I need to display the sales data from the last 5 quarters, along with more column such as current year Vs previous year quarter sales differences.
Ex: My current quarter is 2023Q2, so in my chart, I need to display the current quarter to the previous year same quarter, which is 2022Q2. Likewise, I need to display the remaining quarters as well in table
Please help create a calculation of the sales differences between the current and previous year's same quarters.
My data is like below.
YearQuarter | sum(Sales) |
202101 | 400 |
202102 | 700 |
202103 | 40 |
202104 | 60 |
202201 | 100 |
202202 | 50 |
202203 | 400 |
202204 | 600 |
202301 | 200 |
202302 | 500 |
output expected:
YearQuarter | sum(Sales) | Current vs Previous Quarter diff |
202202 | 50 | -650 |
202203 | 400 | 360 |
202204 | 600 | 540 |
202301 | 200 | 100 |
202302 | 500 | 450 |
Thanks
Hi, you can do it with set analisys.
Here I send you an example code.
SCRIPT:
LOAD * INLINE [
YearMonth, Sales
202101, 1000
202102, 1200
202103, 900
202104, 1100
202105, 1300
202106, 950
202107, 1050
202108, 1400
202109, 1250
202110, 1600
202111, 1350
202112, 1700
202201, 1800
202202, 2000
202203, 1900
202204, 2100
202205, 2200
202206, 1950
202207, 2050
202208, 2400
202209, 2250
202210, 2600
202211, 2350
202212, 2700
];
SET ANALYSIS:
MAX(2022)
Sum({< [YearMonth] = {">=$(=Left(Max([YearMonth]),4)&Num(Right(Min([YearMonth]),1),'00') )<=$(=Max([YearMonth]))"} >} Sales)
MIN(2021)
Sum({< [YearMonth] = {">=$(=Num(Year(Today())-1 & Right('0' & Month(Today()), 2)))<=$(= Max([YearMonth])-100)"} >} Sales)
Consider that if you use as dimension [Year and Month] they will be separated, you should change the dimension.
Regarts.