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: 
JustinDallas
Specialist III
Specialist III

Show %-diff YoY by MonthYear

Hello Folks,

 

I have a bar chart, where I would like to have the dimensions of MonthYear, and percent improvement over the same month from the previous year.

Below is some dummy data: (In the real data there are other months, so 'Above' won't work)

DATA:
LOAD *,
    DayStart(Timestamp(Floor("date"))) AS '%fact_calendar_key'    
;
LOAD *,
Date(Date#(dateString, 'M/DD/YYYY')) AS 'date'
;
LOAD * Inline
[
	'id', 'dateString', 'quantity'
    1, '1/01/2019', 275
    2, '1/02/2019', 180
    3, '1/10/2020', 100
    4, '1/11/2020', 200
    5, '1/25/2021', 50
    6, '1/26/2021', 10
]
;

MasterCalendar: 
LEFT KEEP(DATA)
LOAD 
 DayStart(Floor(Num(TempDate))) AS %fact_calendar_key, 
 Date(DayStart(TempDate)) AS CalDate, 
 Dual(Year(TempDate) &' '& Month(TempDate), MonthStart(TempDate)) AS YearMonth,
 Dual(Year(TempDate), Year(TempDate)) AS Year,
 Dual(Month(TempDate) &' ' & Year(TempDate), MonthStart(TempDate)) As MonthYear,
;

//=== Generate a temp table of dates === 
LOAD 
 Date(mindate + IterNo()) AS TempDate,
 mindate,
 maxdate // Used in InYearToDate() above, but not kept 
WHILE mindate + IterNo() <= maxdate;

//=== Get min/max dates from Field ===/
LOAD
 MIN(FieldValue('%fact_calendar_key', recno()))-1 as mindate,
 MAX(FieldValue('%fact_calendar_key', recno())) as maxdate
AUTOGENERATE FieldValueCount('%fact_calendar_key');

 

 

What I am trying to get to is the below mockup (I made it in Excel):

JustinDallas_0-1612302828132.png

This is because in the data, we have a drop in the quantity from year-to-year.

What I've tried:

I've started with the below Set Analysis just to get something on the screen:

Sum({$<[MonthYear]={"$(=Date(AddYears(Max(MonthYear), -1), 'MMM YYYY'))"}>} quantity )

 

And that gives me this.

JustinDallas_1-1612303470394.png

 

I can only assume that this is because the Max(MonthYear) is Jan 2021, so the red bar gets calculated when the dimension is equivalent to that, and nowhere else.

 

Any help is greatly appreciated

Labels (2)
1 Reply
JustinDallas
Specialist III
Specialist III
Author

In the end, model work was required 😢