I have used the above function for this and it works for everything apart f4rom the current month (for which there is no data). e.g. The chart presents correct data until August but September does not get populated so the above function only qworks up until a point.
I also tried the previous function in my script but was unable to get it to work as i was unsure how to order it as there a number of keys in the fact table.