Hello, what is the proper way of using `FOR PREVIO...
# gooddata-cloud
v
Hello, what is the proper way of using
FOR PREVIOUSPERIOD
? Are there any caveats? Trying to use it like this:
Copy code
SELECT {metric/my_metric} FOR PREVIOUSPERIOD({label/Start_Time.day})
The issue is that it does not show the correct number in the reports. However when I use Compare the period with Previous Period feature in Analyze date filters on
my_metric
I get the correct number. Using the same date dimension, using multiple different time periods.
m
Can you please describe a bit more what you want to achieve and how do your data look like? For previous period should work by shifting the existing data in time (to the future) by a given number (default is 1) of periods. So it will give you data from march as if they were data from april. (And this allows you to use such metric real with data from april to calculate the diffwrence/ratio etc.). While "for previous ..." (without "period" in it) only shifts by the specified granularity (i.e. day or quarter), the "for previous period ..." shifts dynamically based on what is the date granularity used in the report/insight.
v
I would just like to show the metric value for the currently selected time period and the previous one (no matter what time period I currently filter for). So If I have the last 7 days, I would see the last seven days in one column of the table and seven days in another column. It can be just an average score for example in the given time periods. When I do this using the date filter Analyze the number is accurate. However the
FOR PREVIOUSPERIOD
with the default 1 shows different number. So it seems that it works differently. However I want this metric to work because I want to use it in a subsequent calculation.
Copy code
Average Score = SELECT AVG({fact/Review.Score}) WHERE <condition>
Average Score Prev = SELECT Average Score FOR PREVIOUSPERIOD({label/Start_Time.day})
Average Score Prev
shows different (wrong) value from what insight editor shows whey you apply the comparison in date filter
@Michal Hauzírek see attached screenshots for details
m
I see, I am afraid it might not be as easy in MAQL unfortunately. As far as I understand it, the FOR PREVIOUSPERIOD does not have any relation to the currently set date filter. It only dynamically works with the granularity of the insight it is used in. So if you are viewing it by months it would shift by one month, if by days, it would shift by one day. But that is not what you want, I understand. In the GoodData Platform (not GoodDagta Cloud) you could probably overcome this with Disconnected Date modeling technique and calculating the selected period length. But since dates work differently in GD Cloud I am not sure how and if this is even possible at the moment. (I was not able to achieve it so far). Let me try to check internally with other GD folks.
v
Thank you. This is pretty tricky as it is very hard then to have a metric that actually works with any change over time which is very limiting for detecting many different issue. As a change in a metric is a good indicator of a potential issue or an improvement.